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 |
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 |
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 |
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 |
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 |
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}.* |
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 |
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 |
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 |
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 |
| All times are GMT. The time now is 01:57 AM. |
VBulletin, Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.