On 02/12/2011 06:25 AM, meino.cra...@gmx.de wrote:
> 
> Hi,
> 
>  I am trying to instruct sed to insert a line of text before 
>  a matched line. The whole command should fit into one 
>  physical (command) line.
> 
>  Is it possible? And how is it possible?
> 
>  Thank you very much for any hint in advance!
>  Best regards,
>  mcc
> 
> 
> 

Try the ampersand "&" like the example below.

Make a file of phone numbers.
$ cat phone.txt
555-1212
555-1234
555-9999

Then run the following command to prefix the number with 212 and a dash.
$ sed 's/555/212-&/' phone.txt
212-555-1212
212-555-1234
212-555-9999

Try moving the ampersand around the replacement string.  If moved to the
beginning it transposes the numbers.  Note:  The dash was moved to make
the result look better, it has nothing to do with the command.
$ sed 's/555/&-212/' phone.txt
555-212-1212
555-212-1234
555-212-9999




Reply via email to