I have a flat file as follows:
11|aaa 11|bbb|NO|xxx 11|ccc 11|ddd|NO|yyy
For strings that do not contain | NO | I would like to add a line | YES | in the end. Therefore, my file should look like this:
11|aaa|YES| 11|bbb|NO|xxx 11|ccc|YES| 11|ddd|NO|yyy
I am using AIX, and the sed -i option for inline replacements is not available. Therefore, I am currently using the following code for this:
#Get the lines that do not contain |NO| LINES=`grep -v "|NO|" file` for i in LINES do sed "/$i/{s/$/|YES|/;}" file > temp mv temp file done
However, above, since my file contains more than 40,000 lines, it takes about 3 hours. I believe this takes a lot of time because it needs to search every line and write a temporary file. Is there a faster way to achieve this?
source share