Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed - multiline find and replace where one line is empty 1

Status
Not open for further replies.

babcia01

IS-IT--Management
Jul 11, 2002
37
0
0
US
Hi

This code attached here does not work for me and I tried other code and failed so far..What am I missing?

This is what what I want to do with sedscr (used with runsed.sh):

Find "empty line and xxxxx in the next line after the empty line"
if it is found insert cccccc before the empty line which is before the xxxxx.


This is the code of sedscr

/^$xxxxx/{
i\
ccccc line here
}

Can this be done?


the input file is:

aaaaa
bbbbb

xxxxx

I want to get:

aaaaa
bbbbb
ccccc

xxxxx

 
A starting point:
Code:
awk '
NF{print;next}
{getline x;print (x=="xxxxx"?"ccccc":"")"\n"x}
' /path/to/input >output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you very much, I may then swicth from sed to awk but I tested and do not get the empty line before xxxxx .
Thank you for the reply and the suggestion
 
OOps, sorry for the typo:
Code:
awk '
NF{print;next}
{getline x;print (x=="xxxxx"?"ccccc[!]\n[/!]":"")"\n"x}
' /path/to/input >output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top