RE: SUMMARY: Sed Question

From: Cohen, Laurence <Laurence_Cohen_at_sra.com>
Date: Tue Dec 14 2004 - 11:27:27 EST
All, the solution was sent to me by "no spam".  Here is the solution I used.

nawk '{
ARR[NR] = $0
print $0
if ( NR > 3 ) {
	if ( ARR[NR-2] == "I am trying to add a line" && ARR[NR-1] == "after this
text only if" &&
           ARR[NR] == "all lines of text in this message" && ARR[NR] ==
"are found in this order." )
		print "It worked!  I've added the line!"
}' infile


Thanks again for everyone's help!

>  -----Original Message-----
> From: 	Cohen, Laurence
> Sent:	Tuesday, December 14, 2004 11:11 AM
> To:	Cohen, Laurence; 'sunmanagers@sunmanagers.org'
> Subject:	SUMMARY: Sed Question
>
> I was able to use nawk to get this job done.  Thanks for all of the
suggestions.
>
> 	 -----Original Message-----
> 	From: 	Cohen, Laurence
> 	Sent:	Monday, December 13, 2004 2:19 PM
> 	To:	'sunmanagers@sunmanagers.org'
> 	Subject:	Sed Question
>
> 	I'm trying to use sed to edit a file and add a line after finding several
existing lines in a row.  For example, the file contains lines
>
> 	I am trying to add a line
> 	after this text only if
> 	all lines of text in this message
> 	are found in this order.
>
> 	I want this to read
>
> 	I am trying to add a line
> 	after this text only if
> 	all lines of text in this message
> 	are found in this order.
> 	It worked!  I've added the line!
>
> 	I've tried using the N  and a\ commands to do this, but it doesn't seem to
work if you have more than two lines to join.  Any ideas?
>
> 	Thanks!
>
> 	Laurence H. Cohen
> 	ISM System Administrator
> 	SRA International
> 	703-653-5371
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Tue Dec 14 11:39:07 2004

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:41 EST