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

Delete regex and 2 lines after that 1

Status
Not open for further replies.

dstxaix

Programmer
Dec 22, 2005
78
US
I know only a litte bit of scripting and sed and started using awk recently.

I have a scenario where if the first 4 characters of a line are "PASS" I need to delete that line and the 2 lines below that from the file. I was looking at sed and awk one liners page and nothing really suited me for this requirement however they helped me with some of teh other reqs.

I tried

Code:
awk '/^PASS/ { if (substr($0, 0, 4) == "PASS") ;else print }' testfile
and
Code:
awk '/^PASS/{print x};{x=$0}'

They dont seem to work.

Sample data
Code:
TEST
PASS1
ABC
DEF
GHI
PASS2
JKL

MNO

PASS3
PQR

XYZ
123
 
Perhaps this ?
Code:
awk '/^PASS/{getline;getline;next}1' testfile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV - That is perfect. I gave you a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top