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
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 usingrev
as advised above.I can't find a way to do this with sed alone. There is a flag to the s operation specifies to only replace the Nth match, but counting from the end doesn't work.
this is not possible using one simple sed expression. Instead do something like this ie. use bash's string manipulation capabilities:
But if you REALLY need sed then you can run the following command:
Sorry for confusion above by saying that it was not possible. I normally do this kind of stuff in bash using bash's string handling capabilities.