- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk help again
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 09:48 AM
04-17-2003 09:48 AM
Apr 17 03:11:29 guadeloupe smap[15162]: ACCEPTING MESSAGE - INFORMATION FOLLOWS
Apr 17 03:11:29 guadeloupe smap[15162]: HeaderFrom='"ZZZZZ YYYYYY"
Apr 17 03:11:29 guadeloupe smap[15162]: HeaderTo='
Apr 17 03:11:29 guadeloupe smap[15162]: HeaderSubject='Your Perfect Home - New L
istings for 4/17/2003'
Apr 17 03:11:29 guadeloupe smap[15162]: SMTP HostName='smtp.onlinehelp.com'
Apr 17 03:11:29 guadeloupe smap[15162]: SMTP IPAddress='99.9999.999.99'
Apr 17 03:11:29 guadeloupe smap[15162]: SMTP HELO='smtp.onlinehelp.com'
Apr 17 03:11:29 guadeloupe smap[15162]: SMTP MAIL From='ZZZZZZZZ@Seacoast.com'
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 09:54 AM
04-17-2003 09:54 AM
Re: Awk help again
How about something like this, with grep, instead:
# print 1 line of context before and after regexp, with line number
# indicating where the regexp occurred (similar to "grep -A1 -B1")
sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 10:26 AM
04-17-2003 10:26 AM
Re: Awk help again
Fleet Fingered Pete has given you a solution in sed [I love those sed one liners!]. Here is a little Perl snippet that might work:
perl -ne 'print if /HeaderFrom/ .. /HeaderSubject/' maillog
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 11:01 AM
04-17-2003 11:01 AM
Re: Awk help again
Yet another (this time in 'awk'):
# WHO=james
# awk -v WHO=$WHO '/HeaderFrom=/ && $0~WHO,/HeaderSubject=/ {print $0}' filename
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 11:36 AM
04-17-2003 11:36 AM
Re: Awk help again
I want the three lines that are HeaderTo, HeaderFrom and HeaderSubject.
The key is on HeaderTo for the regexp. Sometimes it is
HeaderTo=''
or
HeaderTo='address'
any clues
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 11:39 AM
04-17-2003 11:39 AM
Re: Awk help again
HeaderTo and then grab the line before and the line after.
The problem is the HeaderTo could be either
HeaderTo=''
or
HeaderTo='address'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 11:43 AM
04-17-2003 11:43 AM
Re: Awk help again
Sorry... it's been a looooon week with a 19 hour planned outage this past saturday.... i needed the humor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 11:47 AM
04-17-2003 11:47 AM
Re: Awk help again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 11:51 AM
04-17-2003 11:51 AM
Re: Awk help again
sed 's/beginning/,/end/g'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 11:52 AM
04-17-2003 11:52 AM
Re: Awk help again
Is the name you are looking for an e-mail address in the form of somename@somedomain.com, or are you just looking for somename? Does the HeaderTo= always have single quotes around the name?
The Perl example I gave doesn't look for the name at all. I'll try that again.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 11:53 AM
04-17-2003 11:53 AM
Re: Awk help again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 01:06 PM
04-17-2003 01:06 PM
Re: Awk help again
awk '/HeaderTo=/{ print prev; print $0; getline ; print $0; }/;{prev=$0}' maillog
This will hold the line before in "prev", when HeaderTo is found prev and current line is printed. Then a "getline" reads the next line and prints it.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 01:25 PM
04-17-2003 01:25 PM
Re: Awk help again
OK, try this:
#!/usr/bin/sh
awk -v WHO="HeaderTo=$1" '
{ if ( $0~WHO ) {print LINE;print $0;getline;print $0} else {LINE=$0}
}' filename
exit 0
...pass the argument to match the string that follows "HeaderTo=". Thus if the script were called 'my.sh' do:
# my.sh "'
...or:
# mysh "james"
...etc., depending on the string following the equal sign.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 02:18 PM
04-17-2003 02:18 PM
Re: Awk help again
I attach you a couple of scripts, with the first one the address is embeded in the script itself, in the second one you must type the address in the command line.
- First script.
awk -f file.awk inputfile > outputfile
- Second script
awk -v address="XXXXXXXX@alum\\.colby\\.edu" -f file2.awk inputfile > outputfile
hope this helps.
Frank.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 03:26 PM
04-17-2003 03:26 PM
Re: Awk help again
While I will always think that the forums are the greatest resource there is, I'm supposed to be starting my vacation (and Momma said NOW!). I would attach all the "Handy One Liners for Sed" that Princess Paula originally posted so you might be able to noodle through - but I'm at home, I can't get to my notes - AND MOMMA SAYS NOW!!!
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 05:01 PM
04-17-2003 05:01 PM
Re: Awk help again
I've got you covered. I keep my sed one liners handy at work. I'm at home now, but I found a recent copy from the author's web page. I've posted it as an attachment.
JP
P.S. I understand what it means when Momma says NOW! Enjoy your vacation. :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2003 05:20 PM
04-17-2003 05:20 PM
Re: Awk help again
I knew someone would pick up the slack. I'll send you a post card!
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2003 04:52 AM
04-18-2003 04:52 AM
Re: Awk help again
We support online communities for Universities and Orgs and one of our perks is a email forwarding capabilities and of course the upper management like daily numbers and stats.
the To address could have ' ' around the address or < > or '< >' so I would just like to grab the address within the special chars.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2003 05:18 AM
04-18-2003 05:18 AM
SolutionBased on your last comments, if you could find the lines you want regardless of how they are bounded, using the script I supplied, thusly:
# my.sh "'*<*James>*'*"
...would return matches for:
HeaderTo=James
HeaderTo=
HeaderTo='
HeaderTo='James'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2003 06:14 AM
04-18-2003 06:14 AM
Re: Awk help again
Since you're filtering mail logs, perhaps you like to extract (match) names case-insensitively, so that "James" is the same as "james". If so try this script with your data:
#!/usr/bin/sh
typeset -l WHO="HeaderTo='*<*${1}>*'*"
awk -v WHO=$WHO '
{ if (tolower($0)~WHO) {print LINE;print $0;getline;print $0} else {LINE=$0}
}' filename
exit 0
...now to extract any variation of "jAmEs":
./my.sh jAmEs
Note that you pass one argument representing the name to match.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2003 06:48 AM
04-18-2003 06:48 AM
Re: Awk help again
As always guys thanks for all the responses, comic including and for your efforts and see you at the next request