Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2013

    Unanswered: Printing data within a certain time frame

    Hello all.

    Need a bit of help. It seems fairly easy, but I'm a bit stuck. I'm parsing a log file for all data that's less than or equal to 30 minutes old, sending it to a temp file for reading. How do I store the time value, and use that with awk to get the contents I'm looking for?

    File contents:
    Feb  5 12:01:14 some random data here
    Feb  6 12:02:23 some random data here
    Feb  6 13:30:45 some random data here
    Feb  7 13:03:42 some random data here
    Feb  7 15:23:45 some random data here
    What trying to do
    value=`perl -e 'print scalar localtime( time - 1800 );' | awk '{print $4}'`
    awk -v v=$value '$3>="$v" {print $0}' myfile > myfile.out
    Thanks in advance!

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    If you are determined to use awk, then I'd recommend checking convert date and time to epoch in awk for a good line of thought on how to solve this problem.

    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Sep 2009
    Provided Answers: 1
    You might also write a cron job to add a marker line to the log file every 30 minutes.
    Then the data you are looking for is whatever is there after the last marker record.

  4. #4
    Join Date
    Nov 2013
    Thanks Pat!

    kitaman -- Good idea, it would make it a lot easier to pull the data out based on the marker.

    It's actually working with what I wrote above, with an added grep for the current day / month. It's not pretty, but so far it's doing the job.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts