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!

Printing Lines Until New String is Found 1

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
I am trying to use awk to print lines that contain the string DOWN until a new entry (date) is found on the following line. Ex. I would like to print lines 1-3 below only because line one has the string DOWN and the entry continues until line 3. Line 4 is a new entry that does not contain the string DOWN, so I would skip that entry.

10/01/2003 03:55:18 gsc-fin gsc-fin media id 501171 is in a DOWN drive,
misplaced, write protected or unmountable; attempting
retry with a different media id
10/01/2003 04:35:17 gsc-fin prog-mgt from client prog-mgt: WRN - Could not
reset access time of /raid310/opt/ent/seos/log/seos.audit

Below is the awk script that I have started and it's output.

/DOWN/{if (NF>=8) tape = $7; printf("Please verify the status of volume %d.\n\n", tape) ; print $0}

Output:

Please verify the status of volume 501171.

10/01/2003 03:55:18 gsc-fin gsc-fin media id 501171 is in a DOWN drive,

Desired Output:

Please verify the status of volume 501171.

10/01/2003 03:55:18 gsc-fin gsc-fin media id 501171 is in a DOWN drive, misplaced, write protected or unmountable; attempting retry with a different media id

Any help would be greatly appreciated.

Thanks,

John

 
This is not tested, but may get you started. I assumed any line which starts with a number is a date. You may need to improve this.

/^[0-9]/{flg=0}
/DOWN/{if (NF>=8) tape = $7; printf("Please verify the status of volume %d.\n\n", tape) ; flg=1}
flg{print}


CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
#!/usr/bin/awk -f

/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9] /{flg=0;
if (buf) print buf;
buf=""}
flg==1 {buf=buf " " $0}
/DOWN/ {if (NF>=8) tape = $7;
printf("\n\nPlease verify the status of volume %d.\n\n", tape) ;
flg=1;
buf=$0}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top