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

need to grab field from prevous line

Status
Not open for further replies.

cp2000

Technical User
Dec 31, 2002
81
US
I am trying to grab information from the output of the mailq(postfix) Command. The problems is......The search criteria is on line 2 and the information (message ID) is on line 1. I searched and found several multiple line posts but none that quite cover this. It looks something like.

F0E413FBB 7462 Tue Oct 19 10:52:42 george@internet.com
(connect to mail.hisnet.com[66.11.222.120]: server dropped connection without sending the initial greeting)
george@hisnet.com
 
What have you so far ?
Can you please post more input samples and, obviously, expected result ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I don't know what you're looking for in the second line; let's use "dropped connection" as an example:

Code:
/dropped connection/ { print prev_line "\n" $0 }
{prev_line = $0}
 
here is the script so far:
--------
#!/bin/bash
mailq | tail +2 \
| gawk -F" " ' /.*isnet.com/ { print $1 }' -
--------

The input looks like:
--------
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
43CFE3F82 1298 Tue Oct 19 12:23:35 support@internet.com
(connect to mail.ofnet.com[1.1.1.1]: Connection timed out)
george@ofnet.com

F0E413FBB 7462 Tue Oct 19 10:52:42 george@internet.com
(connect to mail.hisnet.com[66.11.222.120]: server dropped connection without sending the initial greeting)
george@hisnet.com
--------
The output I'm getting is:
--------
george@hisnet.com

--------
The output I'm looking for is
--------
F0E413FBB
--------
 
something like this ?
mailq | gawk '/isnet\.com/{print s;next}{s=$1}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
It will simplify things if we make the record separator a blank line:
[tt]
mailq | gawk 'BEGIN{RS=""} /isnet\.com/ { print $1 }'
[/tt]
 
PHV - yours was almost there
-------
F0E413FBB
F0E413FBB
-------
futurelet -that works - THNX
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top