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!

read output , search for text then print only the 3ed line after

Status
Not open for further replies.

qqqqqq

Technical User
Jan 30, 2000
2
IR
In AIX Korn shell with no nawk access, I would like to run the "tapeutil -f /dev/rmt0 inventory" command, search the output for a line containing the word "Slot" and print the line AND the 3ed line after the line that contains the work "Slot'. If this can be done as a one liner it would be great.
Example of data:
Source Element Address Valid ... No
Media Inverted ................. No
Volume Tag .....................

Slot Address 4116
Slot State ..................... Normal
ASC/ASCQ ....................... 0000
Media Present .................. No
Robot Access Allowed ........... Yes
Source Element Address Valid ... No
Media Inverted ................. No
Volume Tag .....................

Wanted output:
Slot Address 4116
Media Present .................. No

Thank You in Advance for your suggestions. I hope that I was clear and included all needed information.
 
Well if we can use those text strings to find the information, then this should work

Code:
tapeutil -f /dev/rmt0 inventory | egrep '^(Slot Address|  Media Present)'
 
Or if you need the third line no matter what it is

awk '/^Slot/{print;for (i=0;i<3;i++) getline; print}'

CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
CAKIWI,
That is exactly what I wanted. So Perfect.........
I can even change it so that I can choose the next line or even the 5th line.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top