Re: Seeking help with Sed statement.
From: John Savage (rookswood_at_suburbian.com.au)
Date: 05/18/05
- Next message: John Savage: "Re: Seeking help with Sed statement."
- Previous message: David Schwartz: "Re: Newbie question: how to get the stack trace from a dump file"
- In reply to: l3gl3$$_m4r1n3_at_salmahayeksknockers.edu: "Seeking help with Sed statement."
- Next in thread: $p1r17u4l_gyn3c0l0g1$7_at_salmahayeksknockers.edu: "Re: Seeking help with Sed statement."
- Reply: $p1r17u4l_gyn3c0l0g1$7_at_salmahayeksknockers.edu: "Re: Seeking help with Sed statement."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 18 May 2005 00:47:56 GMT
l3gl3$$_m4r1n3@salmahayeksknockers.edu writes:
>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)
- Next message: John Savage: "Re: Seeking help with Sed statement."
- Previous message: David Schwartz: "Re: Newbie question: how to get the stack trace from a dump file"
- In reply to: l3gl3$$_m4r1n3_at_salmahayeksknockers.edu: "Seeking help with Sed statement."
- Next in thread: $p1r17u4l_gyn3c0l0g1$7_at_salmahayeksknockers.edu: "Re: Seeking help with Sed statement."
- Reply: $p1r17u4l_gyn3c0l0g1$7_at_salmahayeksknockers.edu: "Re: Seeking help with Sed statement."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|