Sed insert before character
I have the following homework. I need to enter a certain word, let s call it "exemple" , before every lowercase character in a document. I tryed
sed '/[a-z]/i \exemple' text.txt OUTPUT: 1: exemple 2: same text no changed Can you please help me figure this out? |
The "i" command is for inserting whole lines above the one you matched (and "a" appends them after it). You need to use the "s" command to edit the line itself.
In this case you need to match the character or string you want on the left side of the substitution, and save it in a regex backreference. Then you can insert it into the right-hand-side replacement text. This means you'll probably want to use the -r program option. Don't forget the "g" substitution modifier too if there can be multiple matches on the line (s///g). Here are a few useful sed references. http://www.grymoire.com/Unix/Sed.html http://sed.sourceforge.net/grabbag/ http://sed.sourceforge.net/sedfaq.html http://sed.sourceforge.net/sed1line.txt PS: Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting. |
An easy way of doing it would be using the special character "&".
|
Thank you guys. Solved
|
All times are GMT -5. The time now is 07:33 PM. |