LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed replacing a specific character with a specific number (https://www.linuxquestions.org/questions/linux-newbie-8/sed-replacing-a-specific-character-with-a-specific-number-842325/)

ieatbunnies 11-04-2010 10:08 AM

sed replacing a specific character with a specific number
 
i want to change all the "B's" in a text file to be replaced witha specific number such as"1" but in the same text i would like to replace all the "C's" with "2" and "D's" with 3

Code:

sed 's/b/1/g' $fl.old > $fl
sed 's/c/2/g' $fl.old > $fl
sed 's/d/3/g' $fl.old > $fl

but i know that is not right.

druuna 11-04-2010 10:11 AM

Hi,

Untested, but this should work:

sed -i.bak -e 's/b/1/g' -e 's/c/2/g' -e 's/d/3/g' infile

With the -e option you can string together multiple sed statements.
The -i.bak makes in file changes and saves the original with an added .bak.

Hope this helps.

sycamorex 11-04-2010 10:14 AM

1. You can combine the three commands:

Code:

sed -e 's/b/1/g' -e 's/c/2/g' -e 's/d/3/g' fl.old > fl
Why $? Do you want to pass the file names from variables?


All times are GMT -5. The time now is 09:28 PM.