- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk or Perl advice
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
02-05-2004 03:30 AM
02-05-2004 03:30 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2004 03:33 AM
02-05-2004 03:33 AM
Re: Awk or Perl advice
From "Handy One-Liners for Sed" (attached):
# 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
02-05-2004 03:42 AM
02-05-2004 03:42 AM
Re: Awk or Perl advice
The following will do it:
awk '
/HeaderTo/ && /jmarrion@bcharrispub.com/ {
print lastline
getline
}
{lastline=$0}
' yourfile
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2004 04:06 AM
02-05-2004 04:06 AM
Re: Awk or Perl advice
#!/usr/bin/perl -w
use strict;
use constant TRUE => 1;
use constant FALSE => 0;
my ($s,$prev,$cont) = ('','',TRUE);
while (defined($s =
{
if ($s =~ "^HeaderTo=jmarrion\@bcharrispub.com")
{
print $prev,$s;
if (defined($s =
{
print $s;
}
$cont = FALSE;
}
else
{
$prev = $s;
}
} # while
exit(0);
scan.pl < myfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2004 04:09 AM
02-05-2004 04:09 AM
Re: Awk or Perl advice
Thanks Graham, I am working with yours right now, but I have a question, I just looked at the log with the HeaderTo=, there could be a 'address' or '' or 'Full Name' 'address'. I tried your awk and it didnt retrieve anything, although grep returned about 20 results of HeaderTo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2004 04:14 AM
02-05-2004 04:14 AM
Re: Awk or Perl advice
The line
/HeaderTo/ && /jmarrion@bcharrispub.com/ {
will execute whenever it finds BOTH strings on a line.
Change the strings within the // delimiters to match what you need.
Or add more.
etc.
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2004 04:36 AM
02-05-2004 04:36 AM
Solutionlt09:/tmp 114 > cat file
a
b
c
d HeaderTo=jmarrion@bcharrispub.com
e
f
g HeaderTo=jmarrion@bcharrispub.com
h HeaderTo='jmarrion@bcharrispub.com'
i
j
k
l HeaderTo=jmarrion@bcharrispub.com
lt09:/tmp 115 > perl -ne'BEGIN{sub p{@x>1&&$x[-2]=~m{HeaderTo=[\x27]*jmarrion\@bcharrispub.com}and print@x}}END{push@x,"";p}push@x,$_;p;@x==3&&shift@x' file
c
d HeaderTo=jmarrion@bcharrispub.com
e
f
g HeaderTo=jmarrion@bcharrispub.com
h HeaderTo='jmarrion@bcharrispub.com'
g HeaderTo=jmarrion@bcharrispub.com
h HeaderTo='jmarrion@bcharrispub.com'
i
k
l HeaderTo=jmarrion@bcharrispub.com
lt09:/tmp 116 >
This prints the surrounding lines even if the pattern orrurs in two consequetive lines, with or without quotes
Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2004 05:28 AM
02-05-2004 05:28 AM
Re: Awk or Perl advice
Minimally tested.
awk '/^HeaderFrom/{from=$0}
/^HeaderToj.*marrion@bcharrispub.com/{print from "\n" $0;subj=1;from=""}
(subj)&&/^HeaderSubj/{print $0 "\n";subj=0}' < message_file
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 03:16 AM
02-06-2004 03:16 AM
Re: Awk or Perl advice
For my solution, you would create three files.
Your list of names that you are looking for would go into a file called targets with this format:
TARG yourname@yourcompany.com
You would also create a file called hfht.awk:
BEGIN{count=0;}
/^TARG / {count++;searchit[count]=$2;next}
count==0 {print "Error. No Targets specified";exit}
/HeaderFrom/ {saveline=$0;next;}
/HeaderTo/ {for (idx1 in searchit)
{if (index($0,searchit[idx1])>0) {hit=1; print saveline; print $0;} } }
/HeaderSubject/{if (hit==1) {print $0;print "----";hit=0;next}}
You would also create an executable file called hfht.sh:
cp targets hfht.use
cat searchfile >> hfht.use
awk -f hfht.awk < hfht.use
This will give you output like:
HeaderFrom bob
HeaderTo kmo@atl.hp.com
HeaderSubject Test
----
HeaderFrom bob2
HeaderTo kmo@atl.hp.com
HeaderSubject Test 2
Best regards,
Kent M. Ostby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 04:05 AM
02-06-2004 04:05 AM
Re: Awk or Perl advice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 06:21 AM
02-06-2004 06:21 AM
Re: Awk or Perl advice
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 06:48 AM
02-06-2004 06:48 AM
Re: Awk or Perl advice
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 06:52 AM
02-06-2004 06:52 AM
Re: Awk or Perl advice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2004 07:04 AM
02-06-2004 07:04 AM