Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4572884
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:42:31+00:00 2026-05-21T19:42:31+00:00

I’m trying to work on a logfile, and I need to be able to

  • 0

I’m trying to work on a logfile, and I need to be able to specify the range of dates. So far (before any processing), I’m converting a date/time string to timestamp using date --date "monday" +%s.

Now, I want to be able to iterate over each line in a file, but check if the date (in a human readable format) is within the allowed range. To do this, I’d like to do something like the following:

echo `awk '{if(`date --date "$3 $4 $5 $6 $7" +%s` > $START && `date --date "" +%s` <= $END){/*processing code here*/}}' myfile`

I don’t even know if thats possible… I’ve tried a lot of variations, plus I couldn’t find anything understandable/usable online.

Thanks

Update:

Example of myfile is as follows. Its logging IPs and access times:

123.80.114.20      Sun May 01 11:52:28 GMT 2011
144.124.67.139     Sun May 01 16:11:31 GMT 2011
178.221.138.12     Mon May 02 08:59:23 GMT 2011
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:42:32+00:00Added an answer on May 21, 2026 at 7:42 pm

    Given what you have to do, its really not that hard AND it is much more efficient to do your date processing by converting to strings and comparing.

    Here’s a partial solution that uses associative arrays to convert the month value to a number. Then you rely on the %02d format specifier to ensure 2 digits. You can reformat the dateTime value with ‘.’, etc or leave the colons in the hr:min:sec if you really need the human readability.

    The YYYYMMDD format is a big help in these sort of problems, as LT, GT, EQ all work without any further formatting.

    echo "178.221.138.12     Mon May 02 08:59:23 GMT 2011" \
    | awk 'BEGIN {
    mons["Jan"]=1 ; mons["Feb"]=2; mons["Mar"]=3
    mons["Apr"]=4 ; mons["May"]=5; mons["Jun"]=6
    mons["Jul"]=7 ; mons["Aug"]=8; mons["Sep"]=9
    mons["Oct"]=10 ; mons["Nov"]=11; mons["Dec"]=12
    }
    { 
       # 178.221.138.12     Mon May 02 08:59:23 GMT 2011
       printf("dateTime=%04d%02d%02d%02d%02d%02d\n", 
           $NF, mons[$3], $4, substr($5,1,2), substr($5,4,2), substr($5,7,2) )
    } ' -v StartTime=20110105235959
    

    The -v StartTime is ilustrative of how to pass in (and the matching format) your starTime value.

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.