I have a very huge access.log file of 2 Gb containing apache access logs. The date time format in that is as below :


I want to cut (and not just copy) the logs from this huge file to another file between two time stamps. l am trying this using combination of "cat" and "sed" but it ends up only in copying and not cutting. Please advice. I am having HP-UX server and the access.log file is a dynamic one i.e. access logs are continuously getting appended to the end of file (because apache URL is continuously being hit by users)

Thanks in advance

  • Update your post and put about month: March , May, Apr, I need to know you how to lenght to use May=3 Marc=4 Commented May 17, 2015 at 7:05
  • Do you have bash or korn? Commented May 17, 2015 at 7:08
  • Dear Mohsen...I am not using any shell script,rather i am using individual commands on command line.I have to cut logs on date and time basis so I am not using anything like May=3 March=4
    – Mars
    Commented May 17, 2015 at 8:07

1 Answer 1


I wrote the following script , It read dates.txt and convert all of date to EPOC(timstamp) and print them, Of course i wrote with bash , You need to change name of file and pipe output to a newlogfile:

declare month=(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
while IFS= read -r line <&3; do

    sec1=`echo $line |awk -F/ '{print $1}'`
    sec2tmp=`echo $line |awk -F/ '{print $2}'`
    sec3=`echo $line |awk -F/ '{print $3}' | awk -F: '{print $1}'`
    timesec=`echo $line |awk -F/ '{print $3}' |awk -F: 'BEGIN{ OFS=":";}{print $2,$3,$4}'`
    for i in `seq 0 11`
        real_month=`echo $i+1 |bc`
        if [[ "$tmp" =  "$sec2tmp" ]]


        generated_time="$sec1/$sec2/$sec3 $timesec"
        echo `date --date="$generated_time"  +"%s"`
done 3< dates.txt
  • @Mars , Did you use my script? Commented May 18, 2015 at 13:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .