Replace last characters in each line

sed

I have a csv file with floats ending in a character:

1, 2, 6, 7, "p"
1, 6, 7, 2, "e"

etc.

I'd like to replace "p" with 0 and "e" with 1 for a classification task. That is, I would like:

1, 2, 6, 7, 0
1, 6, 7, 2, 1

For all 8000 lines in my file.

I have tried:

sed -i 's/"p"$/0' filename.csv

and

sed -i 's"p"$0//' filename.csv

but neither work. How can I replace several characters in each line using sed?

Best Answer

sed 's/"p"$/0/;s/"e"/1/' file.txt
Related Question