[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: 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 "\n"}' | 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


Reply to: