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!

FIND STRING-PRINT-GO TO NEXT LINE IF MEETS CRITERIA PRINT IF NOT SEARC 2

Status
Not open for further replies.

keusch

Technical User
Jun 17, 2001
41
US
I want to search for the "Remarks on" and print that line.
test 1 - if the next line (line 2) has a record number = 1, then I want to search again for "Remarks on"
test 2 - if next line (line 2) has $2 == "PD" then I want to search again for "Remarks on"
test 3 - if next line (line 2) has NR >1 then I want to print that line
go to next line (line 3)
repeat for test 1 ,2 and 3
-------here is the awk script - not complete

awk '
/Remarks on/ { # find phrase Remarks on
print $0 # print line
next #go to next line
}
# test 1
$2 == "PD" # if $2 = "PD" go to next search /Remarks on/
# test 2
NR = 1 # if nunber of records = 1 go to next search /Remarks on
# test 3
NR > 1 # if numnber of recors > 1 print line
{ print $0 #
next # if last (test 3) is true then go to next line
# test for 1 ,2 and 3
}

' example.txt > t2.txt

---- here is input
49035063810000 Remarks on PT Test 001 FRAC OIL WAS GELLED-FLUSH W/UNGELLED OIL ISIP 5900, SIP /15
49035063810000 MIN/ 5800
49035063810000 PD #002
49035063810000 Remarks on PT Test 002 FLUSHED W/CLEAR DIESEL OIL, ISIP 5700, SIP /15 MIN/ 5400
49035063810000 PD #003
49035063810000 Remarks on PT Test 003 FLOWED WELL 32 1/2 HRS-REC LO, SOME WTR & COND, GAS DECR TO
49035063810000 887 BY END OF TEST, STABALIZED AT 768 MCFD
4903506381000
49035063810000 PD #004
49035063810000 Remarks on PT Test 004 FRACT W/GEL DIESEL-FLUSHED W/9660 GALS CLEAR DIESEL ISIP
49035063810000 5200 SIP /15 MINS/ 5000 FLOWED 1020 MCFD DECR TO 362 MCFD
49035063810000 W/FRAC FLUID & SMALL AMT OF WTR CLEANED OUT PKR TO PB
49035063810000 10038
49035063810000 PD #005
49035063810000 Remarks on PT Test 005 GAUGES NOT STABALIZED-FLOWED 100 MCFD-1540 MCFD
49035063810000 PD #006
49035201240000 Remarks on IP Test 001 SIGW-IP NOT AVAILABLE
49035201240000
49035201240000 PD #001
49035205830000 Remarks on PT Test 001 FRAC W/125000# 40/60 SD & 175000# 20/40 SD
49035205830000
49035205830000 DST # 001
49035205830000 Show: S Formation: ROCK SPRINGS
49035205890000 Average Injection Rate:
49035206200000
49035206200000 PD #001
49035206200000 Remarks on PT Test 001 GAUGE NOT RPTD



---- this is what I want it to look like
49035063810000 Remarks on PT Test 001 FRAC OIL WAS GELLED-FLUSH W/UNGELLED OIL ISIP 5900, SIP /15
49035063810000 MIN/ 5800
49035063810000 Remarks on PT Test 002 FLUSHED W/CLEAR DIESEL OIL, ISIP 5700, SIP /15 MIN/ 5400
49035063810000 Remarks on PT Test 003 FLOWED WELL 32 1/2 HRS-REC LO, SOME WTR & COND, GAS DECR TO
49035063810000 887 BY END OF TEST, STABALIZED AT 768 MCFD
49035063810000 Remarks on PT Test 004 FRACT W/GEL DIESEL-FLUSHED W/9660 GALS CLEAR DIESEL ISIP
49035063810000 5200 SIP /15 MINS/ 5000 FLOWED 1020 MCFD DECR TO 362 MCFD
49035063810000 W/FRAC FLUID & SMALL AMT OF WTR CLEANED OUT PKR TO PB
49035063810000 10038
49035063810000 Remarks on PT Test 005 GAUGES NOT STABALIZED-FLOWED 100 MCFD-1540 MCFD
49035201240000 Remarks on IP Test 001 SIGW-IP NOT AVAILABLE
49035205830000 Remarks on PT Test 001 FRAC W/125000# 40/60 SD & 175000# 20/40 SD
49035206200000 Remarks on PT Test 001 GAUGE NOT RPTD
 
Assuming you said NR when you meant NF, this script may something close to what you want.
Code:
/Remarks on/ {
   print
   if (!(getline > 0)) exit
   while (NF > 1 && $2 != "PD") {
     print
     if (!(getline > 0)) exit
   }
}
Hope this helps. CaKiwi
 
Thanks for your help. It works fine. (I realize the using the wrong term NR after it was sent).
Now I will readup on getline!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top