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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inerting lines between pattern 1

Status
Not open for further replies.

damanbagga

Technical User
Aug 28, 2004
4
US
I have a pattern of text below. I want to insert line with text <E. > if missing between two lines with text <D. %> and <Answer:>

I have i/p like below --->

C. Apple
D. Some variable text here
Answer: C

I want o/p like below --->

C. Apple
D. Some variable text here
E. <----
Answer:


<---- Note, I want <E. > to be inserted if not present between lines <D. %> and <Answer:>

 
Something like this ?
awk '
/^Answer:/{if(last!="E.")print "E."}
{print;last=$1}
' /path/to/input >output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top