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

Recommended Answers

All 2 Replies

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

thank you a lot for your answer , it worked

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.