Re: Seeking help with Sed statement.
From: John Savage (rookswood_at_suburbian.com.au)
Date: Wed, 18 May 2005 00:47:56 GMT
>I want to insert the line "Insert" before the first line beginning with a
>plus. To my understanding of sed it would be:
>cat file | sed -e '/^+/ i\Insert\'
>But that's not working. Note: I've been able to write the fix in awk,
>but it's annoying me that I can't do it in sed.
>Can anyone provide insight?
Your query prompted me to reinvestigate the 'i' command as although I have
been using sed for many years I had resigned myself to never being able
to get the 'i' command to work in one-liner scripts! After a few trials, I
now have the answer: break it up into a number of -e arguments, viz.,
sed -e '/^+/i\' -e 'Insert' file
or, sed -e '/^+/'i\\ -e 'Insert' file
As expected, identical one-liner syntax works for the 'a' command, also.
Note for MSDOS users: I found that the \ must not be inside any quotes,
i.e., you must use -e /^+/i\ OR "/^+/"i\ OR "/^+/i"\ but not "/^+/i\"
So, Daniel, you provided the incentive for me to master 'i' in one-liners
at last! In Unix, the usual work-around is to split the command over two
lines (but even this cop out is not available in the MSDOS OS).
-- John Savage (my news address is not valid for email)