AIX script to parse records inside a file

I need to write an AIX script to parse the records inside the file /var/log/mail.log.  Here are a few records from the log.

Aug  1 13:51:33 domain sendmail[37804]: NAA99708: to=user@domain2.com, ctladdr=fr
ank (205/1), delay=00:00:01, xdelay=00:00:00, mailer=relay, relay=mail.domain.co
m. [::ffff:192.168.25.3], stat=Sent (2.6.0  <200708011851.NAA99708@domain.domain
.com> Queued mail for delivery)
Aug  1 13:51:34 domain sendmail[91206]: NAA56130: to=user@domain2.com, ctladdr=f
rank (205/1), delay=00:00:01, xdelay=00:00:01, mailer=relay, relay=mail.domain.c
om. [::ffff:192.168.25.3], stat=Sent (2.6.0  <200708011851.NAA56130@domain.domain.com> Queued mail for delivery)
Aug  1 13:51:34 domain sendmail[99712]: NAA74982: to=user@domain2.com, ctladdr=fr
ank (205/1), delay=00:00:01, xdelay=00:00:01, mailer=relay, relay=mail.domain.co
m. [::ffff:192.168.25.3], stat=Sent (2.6.0  <200708011851.NAA74982@domain.domain.com> Queued mail for delivery)

What I want out of it is:
Aug  1      13:51:34        to=user@domain2.com      <200708011851.NAA74982@domain.domain.com>

Can anyone help?  I do not know where to begin.  I am a novice at AIX scripts.
khuff71Asked:
Who is Participating?
 
amit_gConnect With a Mentor Commented:
See if this works for you...

awk '{print $1 " " $2 " " $3 " " $7 " " $17}' YourFileName
0
 
khuff71Author Commented:
That did it.  Now I need to be able to print only yesterday's date.  Can you help with that?
0
 
Kent OlsenConnect With a Mentor Data Warehouse Architect / DBACommented:

Hi khuff71,

Data math in unix shells is a bit tough.  If you can pass the date to a script you can feed it through grep.

  grep 'Aug 1' log | awk '{print $1 " " $2 " " $3 " " $7 " " $17}'

As a script, it's:

#
  grep $1 log | awk '{print $1 " " $2 " " $3 " " $7 " " $17}'


and called as:

  getfromlog "Aug 1"



Kent
0
All Courses

From novice to tech pro — start learning today.