Date and Time comparison using shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date and Time comparison using shell script
# 8  
Old 01-08-2012
Quote:
Originally Posted by buzzusa
awk and nawk are getting the same error.

awk: Function systime is not defined.

The input line number is 1. The file is abc.log.
The source line number is 2.

Thanks
Instead of systime() use strftime("%s") and give it a try!

Code:
awk -F"|" '{ x=$1;y=$2;
  diff=strftime("%s")-mktime(substr(x,0,4)OFS substr(x,5,2)OFS substr(x,7,2)OFS substr(y,0,2)OFS substr(y,3,2)" 00")
  print diff/3600 " Hours"
}' infile

--ahamed
# 9  
Old 01-08-2012
strftime, systime and mktime are getting the same errors in AIX. We don't have C/C++ compilers on these servers. I don't know how to call these system calls.
# 10  
Old 01-08-2012
Perl.

Code:
perl -ne 'use Time::Local;
$diff=time-timelocal(substr($_,13,2),substr($_,11,2),substr($_,9,2),substr($_,6,2),substr($_,4,2)-1,substr($_,0,4));
print $diff ."\n";' input.txt


Last edited by balajesuri; 01-08-2012 at 09:32 PM..
# 11  
Old 04-23-2012
If it's feasible for you to use an external helper tool, check out my dateutils (http://hroptatyr.github.com/dateutils).

ddiff -i '%Y%m%d|%H%M%S' "20111220|102000" now -f '%H'
=> 3003

The -i is the input format, -f the output format (difference in hours), and "20111220|102000" is your F1|F2, now is the value to compute the difference from.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date time difference in UNIX shell script

There are 2 dates, Tue Oct 1 13:40:19 2013 Sun Sept 30 10:26:23 2013 I have multiple dates like the above one. How do I calculate the date time difference and display in another column in Shell script. Please help. (3 Replies)
Discussion started by: tanmoysays
3 Replies

2. Shell Programming and Scripting

Date / Time difference in shell script

Request ID GMDCOMTM GMDRRSTIME GMDRESTIME <36812986> : : :I want to display the date -time difference in other fields. Above I have given for only 1 record. I want to calculate for all the records. (GMCOMTM - GMDRRSTM) ,(GMDRRSTM-GMDRESTM) and... (5 Replies)
Discussion started by: ghosh_tanmoy
5 Replies

3. Shell Programming and Scripting

Date / Time difference in shell script

================================================================================ Request ID GMDCOM TIME GMDRRS TIME COM-RRS ================================================================================ <36812974> Tue Oct 1 13:32:40 2013 Tue Oct 1 20:36:42 2013... (1 Reply)
Discussion started by: ghosh_tanmoy
1 Replies

4. Shell Programming and Scripting

How to do simple date (time) calculation in shell script?

Hi, I'm looking for a way to do a simple math calc during a shell script as a means of logging how long a particular task takes. For example... STARTTIME=whenever this script starts ./path/to/command.sh >>logfile.log TOTALTIME=<time at this stage of the script after above command... (7 Replies)
Discussion started by: nbsparks
7 Replies

5. Shell Programming and Scripting

Is it possible to get the date and time of mail which we get into our inbox using shell script?

Hello All, I need a script which extarct the date and time of the mail which is there in our inbox... I can export the mail copy into desktop making it as a textfile or something like that.. So is there anyway to get the date and time from that? (3 Replies)
Discussion started by: smarty86
3 Replies

6. Homework & Coursework Questions

Date comparison with 'string date having slashes and time zone' in Bash only

1. The problem statement, all variables and given/known data: I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format . I have developed a log analysis command line utility that displays... (1 Reply)
Discussion started by: TariqYousaf
1 Replies

7. Shell Programming and Scripting

Date comparison in file to system time

I have a CSV (comma separated vaule) file whose entries resemble Area,\\ntsvsp02\vmcs\download\files\Areas.dat,1,20090303,0,Import Complete,2009-03-02 04:23:00 Product,\\ntsvsp02\vmcs\download\files\items.dat,1,20090303,0,Import Complete,2009-03-02 04:23:00... (3 Replies)
Discussion started by: zainravi
3 Replies

8. Shell Programming and Scripting

shell script to find latest date and time of the files

Hi everyone, Please help:) I have a list of 1000 different files which comes daily to the directory.Some of the files are not coming to the directory now. I need to write a shell script to find the latest date and time of the files they came to the directory. The files should be unique.... (1 Reply)
Discussion started by: karthicss
1 Replies

9. Shell Programming and Scripting

Execute a part of shell script only after particular date and time

I have created a simple shell script... say test.sh Contents of test.sh ================ service named restart cp /etc/imp.conf /backup/test/ #-- if date > 15 July 2007 11:23 pm , then only issue the commans below, else exit --- cp /etc/secondimp.conf /backup/test/ rm -f... (2 Replies)
Discussion started by: fed.linuxgossip
2 Replies

10. Shell Programming and Scripting

Help with time comparison shell script for HP-UX

I am using Korne Shell in HP-Ux. Can someone give me and idea on how I can write a shellscript on how to do this please:- On our HP-UX server, a batch file is run every evening at about 6:30pm. The first step of this batch file will touch an empty "flag" file to indicate that the batch has... (6 Replies)
Discussion started by: gummysweets
6 Replies
Login or Register to Ask a Question