AIX script to parse records inside a file

Posted on 2007-08-01
Last Modified: 2013-12-20
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:, ctladdr=fr
ank (205/1), delay=00:00:01, xdelay=00:00:00, mailer=relay,
m. [::ffff:], stat=Sent (2.6.0  <200708011851.NAA99708@domain.domain
.com> Queued mail for delivery)
Aug  1 13:51:34 domain sendmail[91206]: NAA56130:, ctladdr=f
rank (205/1), delay=00:00:01, xdelay=00:00:01, mailer=relay, relay=mail.domain.c
om. [::ffff:], stat=Sent (2.6.0  <> Queued mail for delivery)
Aug  1 13:51:34 domain sendmail[99712]: NAA74982:, ctladdr=fr
ank (205/1), delay=00:00:01, xdelay=00:00:01, mailer=relay,
m. [::ffff:], stat=Sent (2.6.0  <> Queued mail for delivery)

What I want out of it is:
Aug  1      13:51:34      <>

Can anyone help?  I do not know where to begin.  I am a novice at AIX scripts.
Question by:khuff71
    LVL 58

    Accepted Solution

    See if this works for you...

    awk '{print $1 " " $2 " " $3 " " $7 " " $17}' YourFileName

    Author Comment

    That did it.  Now I need to be able to print only yesterday's date.  Can you help with that?
    LVL 45

    Assisted Solution


    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"


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
    I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now