Take file A, find the first line beginning with a 150,
append a line of text at that point and then write out
file A (all of it) with the newly inserted line.
Thanks for any help.
(Apologies if this seems a dumb question, but it's Friday afternoon
and I'm fed up with the manual pages...)
/^150/a\
<THE LINE YOU WANT TO INSERT>
--
John Cornelius
(...!sdcsvax!piaget!jc)
If the pattern /^150/ is only going to occur once in the input, then it's
easy:
/^150/a\
line-of-text-to-append-here
Otherwise, you could try using two loops in the script as follows:
:loop1
/^150/{
a\
line-of-text-to-append-here
b loop2
}
n
b loop1
:loop2
n
b loop2
--
Anders Weinstein <awei...@DIAMOND.BBN.COM>
This will append the text after every line beginning with '150'.
I cannot find a brilliant, elegant solution (but then, I'm neither
brilliant nor elegant), but I found a nice crufty one:
(don't even attempt this in csh! ;-)
$ sed -n '/^150/ {
> =
> q
> } ' filename
will write the number of the first line on which /^150/ occurs. You
can try to work out the substitution of one sed as input for another;
I settled for:
$ line=`sed -n '/^150/ {
> ... filename`
$ sed ''$line' a\
> new text, remember\
> to escape newlines
> ' filename
The two single quotes before $line are necessary.
Hope someone does better; unless you have an overwhelming need for sed,
this is easier in awk.
-- kab
% cat foo.sed
:notyet
/^150/{a\
some\
new\
text
b copy
}
n
b notyet
:copy
n
b copy
% sed -f foo.sed
...
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP: seismo!mimsy!chris ARPA/CSNet: ch...@mimsy.umd.edu