Issue
I have a csv file and I am trying to substitute the last letter for a word... The input is
1111;AAA;... (more columns);A1a;A
2222;XXX;... (more columns);T3g;B
...(more rows)
4564;AdA;... (more columns);G1a;A
33321;B1X; ... (more columns);T3g;B
And I want to replace A for "Avocado" and B for "Banana"...
I tried
#sed -e "s/;A$/;C/g" file.csv
But doesn't work, any advice, please?
Solution
Is the following what you're trying to achieve?
tink@host:~/tmp$ sed 's/A$/Avocado/;s/B$/Banana/' file.csv
1111;AAA;... (more columns);A1a;Avocado
2222;XXX;... (more columns);T3g;Banana
... (more rows)
...(more rows)
4564;AdA;... (more columns);G1a;Avocado
33321;B1X; ... (more columns);T3g;Banana
If that looks correct, and you want to change in-file, add a -i
to sed.
If you want a new file, add a > new_file
to the end of the line.
Answered By - tink Answer Checked By - Willingham (WPSolving Volunteer)