bash - How do I replace the last character and insert a character to the beginning of a string? -
say have text file follows:
accio. aguamenti. alohomora. aparecium.
what i'd is:
-accio! -aguamenti! -alohomora! -aparecium!
this i've tried:
sed 's/.*[a-z]/-&!/g'
which yields:
-accio!. -alohomora!.
which pretty close not need. help?
you need use capturing group exclude character @ end:
$ sed 's/^\(.*\)\.$/-\1!/' file
or in 2 steps:
$ sed -e 's/\.$/!/' -e 's/.*/-&/' file
Comments
Post a Comment