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

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -