FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 05-29-2008, 01:26 PM
kj
 
Default Simple awk question

But I cannot find it in my awk book (O'Reilly's sed&awk).

I'm trying to make three columns out of a postfix mail log. Queue ID,
From address, and remote server response for certain situations (it's
already grepped down to that).


awk '{print $7" "$6" "$17}'

$17 is the first word of the remote server response, I need to include
everything from $17 onwards to the end of the line into the third field.


How do I specify that?

Thanks
--kj


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 05-29-2008, 02:45 PM
John Allen
 
Default Simple awk question

kj wrote:

But I cannot find it in my awk book (O'Reilly's sed&awk).

I'm trying to make three columns out of a postfix mail log. Queue ID,
From address, and remote server response for certain situations (it's
already grepped down to that).


awk '{print $7" "$6" "$17}'

$17 is the first word of the remote server response, I need to include
everything from $17 onwards to the end of the line into the third field.


How do I specify that?


Use Perl

Thanks
--kj





--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 05-29-2008, 05:44 PM
kj
 
Default Simple awk question

John Allen wrote:

kj wrote:

But I cannot find it in my awk book (O'Reilly's sed&awk).

I'm trying to make three columns out of a postfix mail log. Queue ID,
From address, and remote server response for certain situations (it's
already grepped down to that).


awk '{print $7" "$6" "$17}'

$17 is the first word of the remote server response, I need to include
everything from $17 onwards to the end of the line into the third field.


How do I specify that?


Use Perl

Thanks
--kj







I would love to - I'd have to learn it first I did figure it
out,eventually. This is ugly, and most likely the wrong way to do it,
but it works. It sorts it in order of the sender:


grep bounced /var/log/mail.log | awk '{printf "%s, %s ", $6,$7; { for
(i=17; i<=NF; i=i+1) printf "%s ", $i } print "
"}' | sed -e 's/:,/,/'
-e 's/to=<//' -e 's/>,/,/' | grep -v ^$ | sort -k2 > /home/kj/bounces.csv



--kj


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 05-29-2008, 09:02 PM
Alfredo Finelli
 
Default Simple awk question

On Thursday 29 May 2008 19:44, kj wrote:
> [...]
> >> I'm trying to make three columns out of a postfix mail log. Queue
> >> ID, From address, and remote server response for certain
> >> situations (it's already grepped down to that).
> >>
> >> awk '{print $7" "$6" "$17}'
> >>
> >> $17 is the first word of the remote server response, I need to
> >> include everything from $17 onwards to the end of the line into
> >> the third field.
> [...]
> I did figure it out,eventually. This is ugly, and most likely the
> wrong way to do it, but it works. It sorts it in order of the sender:
>
> grep bounced /var/log/mail.log | awk '{printf "%s, %s ", $6,$7; { for
> (i=17; i<=NF; i=i+1) printf "%s ", $i } print "
"}' | sed -e
> 's/:,/,/' -e 's/to=<//' -e 's/>,/,/' | grep -v ^$ | sort -k2 >
> /home/kj/bounces.csv

Out of curiosity I tried a different way, using 'cut' and without
using 'awk'. Here is an example pipeline:

$ echo word1 word2 word3 word4 word5 word6 word7 word8 server message
here | cut -d " " -f "3,5,9-" | sed -e 's/ /,/1' -e 's/ /,/1'
word3,word5,server message here
$

Best regards,

Alfredo


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 05-30-2008, 09:06 AM
John Allen
 
Default Simple awk question

Alfredo Finelli wrote:

On Thursday 29 May 2008 19:44, kj wrote:


[...]


I'm trying to make three columns out of a postfix mail log. Queue
ID, From address, and remote server response for certain
situations (it's already grepped down to that).

awk '{print $7" "$6" "$17}'

$17 is the first word of the remote server response, I need to
include everything from $17 onwards to the end of the line into
the third field.

[...]
I did figure it out,eventually. This is ugly, and most likely the
wrong way to do it, but it works. It sorts it in order of the sender:


grep bounced /var/log/mail.log | awk '{printf "%s, %s ", $6,$7; { for
(i=17; i<=NF; i=i+1) printf "%s ", $i } print "
"}' | sed -e
's/:,/,/' -e 's/to=<//' -e 's/>,/,/' | grep -v ^$ | sort -k2 >
/home/kj/bounces.csv



Out of curiosity I tried a different way, using 'cut' and without
using 'awk'. Here is an example pipeline:


$ echo word1 word2 word3 word4 word5 word6 word7 word8 server message
here | cut -d " " -f "3,5,9-" | sed -e 's/ /,/1' -e 's/ /,/1'
word3,word5,server message here
$



Here is some sample Perl.

grep bounced /var/log/mail.log | perl -p -e 's|w+ w+ w+ w+ w+ w+ (w+) (w+) w+ w+ w+ w+ w+ w+ w+ w+ (.*)|2 1 3|g'


Best regards,

Alfredo






--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 05-30-2008, 09:42 AM
"Javier Barroso"
 
Default Simple awk question

On Fri, May 30, 2008 at 11:06 AM, John Allen <john.allen@dublinux.net> wrote:

Here is some sample Perl.



grep bounced /var/log/mail.log | perl -p -e 's|w+ w+ w+ w+ w+ w+ (w+) (w+) w+ w+ w+ w+ w+ w+ w+ w+ (.*)|2 1 3|g'


Note about you could resume this regex with {} feature:

w+ w+ == (w+ ){2}

and if you don't want to capture this, use start de group with (?:
The regex could be:

(?:w ){6} (w+) (w+) (?:w ){8}.*
 
Old 05-31-2008, 01:13 AM
Andrew Sackville-West
 
Default Simple awk question

On Fri, May 30, 2008 at 10:06:48AM +0100, John Allen wrote:
...


> Here is some sample Perl.

...must ...not ...look...

>
> grep bounced /var/log/mail.log | perl -p -e 's|w+ w+ w+ w+ w+ w+ (w+) (w+) w+ w+ w+ w+ w+ w+ w+ w+ (.*)|2 1 3|g'

ACK! now my eyes are bleeding again...

A
 
Old 05-31-2008, 02:45 PM
Florian Kulzer
 
Default Simple awk question

On Fri, May 30, 2008 at 18:13:30 -0700, Andrew Sackville-West wrote:
> On Fri, May 30, 2008 at 10:06:48AM +0100, John Allen wrote:
> ...
>
>
> > Here is some sample Perl.
>
> ...must ...not ...look...
>
> >
> > grep bounced /var/log/mail.log | perl -p -e 's|w+ w+ w+ w+ w+ w+ (w+) (w+) w+ w+ w+ w+ w+ w+ w+ w+ (.*)|2 1 3|g'
>
> ACK! now my eyes are bleeding again...

Come on, it is not that bad. A sample of Python, on the other hand,
could even kill you:

Wenn ist das Nunstruck
git und Slotermeyer?
Ja!...
Beiherhund

das Oder

die
Flipperwaldt
gersput!

--
Regards, | http://users.icfo.es/Florian.Kulzer
Florian |


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 05-31-2008, 05:29 PM
Andrew Sackville-West
 
Default Simple awk question

On Sat, May 31, 2008 at 04:45:25PM +0200, Florian Kulzer wrote:
> On Fri, May 30, 2008 at 18:13:30 -0700, Andrew Sackville-West wrote:
> > On Fri, May 30, 2008 at 10:06:48AM +0100, John Allen wrote:
> > ...
> >
> >
> > > Here is some sample Perl.
> >
> > ...must ...not ...look...
> >
> > >
> > > grep bounced /var/log/mail.log | perl -p -e 's|w+ w+ w+ w+ w+ w+ (w+) (w+) w+ w+ w+ w+ w+ w+ w+ w+ (.*)|2 1 3|g'
> >
> > ACK! now my eyes are bleeding again...
>
> Come on, it is not that bad.

Oh, I know, I was just providing the obligatory perl joke...

> A sample of Python, on the other hand,
> could even kill you:
>
> Wenn ist das Nunstruck
> git und Slotermeyer?
> Ja!...
> Beiherhund
>
> das Oder
>
> die
> Flipperwaldt
> gersput!

HA HA! The funniest joke in the world!

A
 
Old 06-02-2008, 11:45 AM
Axel Schlicht
 
Default Simple awk question

kj wrote:

But I cannot find it in my awk book (O'Reilly's sed&awk).

I'm trying to make three columns out of a postfix mail log. Queue ID,
From address, and remote server response for certain situations (it's
already grepped down to that).


awk '{print $7" "$6" "$17}'

$17 is the first word of the remote server response, I need to include
everything from $17 onwards to the end of the line into the third field.


How do I specify that?

Thanks
--kj


Hi, IICR you can't go beyond $9 - maybe ${10}will work, not sure here.
So split the line into an array (using split) and print the respective
fields.

Split etc. is in the O'Reilly book.

HTH

Axel


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 06:51 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org