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

Pattern Deletion 1

Status
Not open for further replies.

ng1

Technical User
Aug 22, 2007
39
0
0
US
I want to find a pattern. Then I want to compare string 4 of the line with the pattern in it to string 4 of the line above it. If those 2 strings match, I want to delete both lines.

I know this will delete line with pattern and line above but I don't know how to add the step of matching up string 4.

awk ‘ /UNDO/{x=””;next}
{if(x)print x;x=$0}
END{if(x)print x} ‘ FILE
 
Typed, untested:
Code:
awk '/UNDO/&&s4==$4{x="";next}
{if(x)print x;x=$0;s4=$4}
END{if(x)print x}' FILE

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV. I am checking it out right now.
 
Works like a charm!! Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top