Linux + sed – replace only the right most side char of string

linuxsed

I have linux machine red-hat 5.1

how to replace only the right single char (most side of string)

example from my sed syntax (not good because its replaced both "a" chars)
l

 echo machine1a | sed s'/a/b/g'

 mbchine1b

But the requested answer should be – machine1b
and not mbchine1b

Best Answer

You can use the end-of-pattern-space pattern. The pattern $ matches the null string at the end of the pattern space. With this pattern you can avoid using rev as advised above.

  $ echo machine1a | sed 's/a$/b/'
  machine1b
Related Topic