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

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -