Hello everyone

i have a text file that contains something like this.

1 AC AT RR cOO
2 EE cFF HGB cEVY
3 WDU RWS cTY NBE

but it contains a lot of rows and that's an example of the data

what i want to do is to to create another text file using a shell script from this text file with these modifications:
1-let the same ordering of the same file
2-change each value that contains c to without c
3-add c to each value that does not contain c

e.g(1 AC AT RR cOO will become 1- cAC cAT cRR OO)

thanks in advance

Edited 5 Years Ago by weblover: n/a

sed can do it. The trick is to deal with the 'c' so that sed doesn't remove it entirely until the new 'c' are added in. That's the point of the '%' in the first and last clauses of the script. I'm assuming that the leading digits in your example are line numbers and should never be changed. That allowed me to pay attention to leading white space in each token.

Here's my one liner:

sed -e 's/c\([^ ]*\)/%\1/g' -e 's/ \([^%][^ ]*\)/ c\1/g' -e 's/%//g' < $infile > %outfile

Edited 5 Years Ago by griswolf: n/a

This question has already been answered. Start a new discussion instead.