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!

modify field before output

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
i'm trying to extract 2 fields from an email message, modify one of them before outputting both to another text file.

my input file is:

Return-Path: <root@netsaint.netglobalis.cl>
Delivered-To: visp@bazuca.com
Received: (qmail 31457 invoked from network); 10 Sep 2002 22:11:25 -0000
Received: from unknown (HELO netsaint.netglobalis.cl) (200.14.80.35)
by mailbazuca.bazuca.com with SMTP; 10 Sep 2002 22:11:24 -0000
Received: (from root@localhost)
by netsaint.netglobalis.cl (8.11.6/8.11.6) id g8AMDeN22069
for bazuca@netsaint.netglobalis.cl; Tue, 10 Sep 2002 18:13:40 -0400
Date: Tue, 10 Sep 2002 18:13:40 -0400
From: root <root@netsaint.netglobalis.cl>
Message-Id: <200209102213.g8AMDeN22069@netsaint.netglobalis.cl>
To: bazuca@netsaint.netglobalis.cl
Subject: Reporte conexiones Bazuca.com

2002/09/09;08:27:20;1384;R;125896542@bazuca.com;22344401;6006006045
2002/09/09;08:27:20;1100;R;3456789k@bazuca.com;22344401;6006006045
2002/09/09;08:27:20;500;R;147433042@bazuca.com;22344401;6006006045

and my output file needs to read:

1384;125896542
1100;3456789k
500;147433042

many thanks
 
I'm on a hybrid trip tonight.
You don't see many like this thank goodness.

sed '/^Ret.*/, /^Subj.*\.com/d' f.txt | awk -F&quot;;&quot; ' {
gsub(/@.*/,&quot;&quot;,$0)
if (length($3)) {
printf &quot;%s;%s\n&quot;, $3,$5
}
}' > op.txt

OP:
1384:125896542
1100:3456789k
500:147433042
 
Hi markbazuca,

#!/usr/bin/awk -f
BEGIN { FS=&quot;[;@]&quot;; }

# Use the blank line before message body as a starting point.
NF==0{
while ( ( getline ) > 0 )
{
print $3 &quot;;&quot; $4;
}
}

Grant.
 
Hi -

This combines marsd's code with Grant's blank line idea.

#! /usr/bin/awk -f
BEGIN {
FS = &quot;;&quot;
}
/^Ret.*/,/^$/ {
next
}
{
gsub(/@.*/,&quot;&quot;,$0)
if (length($3)) {
printf &quot;%s;%s\n&quot;, $3,$5
}
} Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top