Replace characters infile with sed

I have several files in a directory that look like this:

jacket-n	r
potential-n	-
outcome-n	f
reputation-n	b

I want to replace the characters in the second column with certain numbers. For instance, I want the letters 'f', 'r' and 'b' in the second column to replaced with 0 and I want the symbol '-' in the second column to be replaced with 1.

The result would be this:

jacket-n	0
potential-n	1
outcome-n	0
reputation-n	0

I have tried the following sed:

sed -i.bak -e 's/-/1/' -e 's/b/0' -e 's/f/' -e 's/r/0' input

but it does not work.
Any suggestions?

It seems that you only want to change the last character on each line, but you don't restrict the search REs to match EOL and three of your substitutions are missing closing slashes. Try:

sed -i.bak -e 's/-$/1/' -e 's/[bfr]$/0/' input
1 Like