Seeking help with Sed statement.

l3gl3$$_m4r1n3_at_salmahayeksknockers.edu
Date: 05/15/05


Date: Sun, 15 May 2005 19:30:51 GMT

I need help with a sed statement.

The problem: Insert a single line of text before the first instance of a
string in a file. The first character of the string is always the same,
the rest, variable. There may be several lines of this string in the
variable-length file. Example:

a
b
c
d
+something
+anything

- 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?

-- 
.............................................................................
"War is an ugly thing, but not the ugliest of things;  The decayed and 
 degraded state of moral and patriotic feelings which thinks that nothing
 is worth war is much worse.  A man who has nothing for which he is willing 
 to fight, nothing which is more important than his own personal safety, 
 is a miserable creature and has no chance of being free unless made and 
 kept so by the exertions of better men than himself"
                                                          - John Stuart Mill
.............................................................................
dswan@m3m3t1ccand1ru.com                        http://www.memeticcandiru.com


Relevant Pages

  • Seeking help with Sed statement.
    ... Insert a single line of text before the first instance of a ... The first character of the string is always the same, ... variable-length file. ... but not the ugliest of things; The decayed and degraded state of moral and patriotic feelings which thinks that nothing is worth war is much worse. ...
    (comp.unix.shell)
  • Re: Regular expression fun. Repeated matching of a group Q
    ... from which I'm attempting to extract the date, ... then matches the tags between the date and the first instance of a time ... but then group 4 grabs all the remaining string. ... Any Python regexp gurus with a hint would be greatly appreciated. ...
    (comp.lang.python)
  • Re: newline and tab Not Working in PHP 5.0.3 | Apache 2.0.52 | Windows XP Pro
    ... > echo $string; ... > The first instance is for a line break such that the words are ... To do a line break in HTML you need to use the tag, ...
    (comp.lang.php)
  • Regular expression fun. Repeated matching of a group Q
    ... from which I'm attempting to extract the date, ... then matches the tags between the date and the first instance of a time ... but then group 4 grabs all the remaining string. ... Any Python regexp gurus with a hint would be greatly appreciated. ...
    (comp.lang.python)
  • Need formulas for finding text strings
    ... I need a formula that returns the cell location of the first instance ... of a text string that I specify in a column listing. ...
    (microsoft.public.excel.programming)