Monday, February 17, 2014

How to find difference between time from 2 file

www.unixbabuforum.in I have 2 file . One file called a.log created at  Feb 21  10:46:51 IST 2009 .And another file called b.log created at  Feb 22 01:46:51 IST 2009 . How do i find time difference between a.log file and b.log file. 


www.unixbabuforum.in"yest" is very useful command for time difference 
yest is a command line date/time manipulation and formatting program, 
very useful in scripts. You can easily add or subtract days, hours 
and/or minutes from a specified date. Supports all date(1) output 
formats plus more. 

download "yest" from 
http://sourceforge.net/projects/yest/

www.unixbabuforum.inUse can use perl... 
$ cat lt.sh 
get_age() 

perl -e '@attrs1 = stat($ARGV[0]); 
@attrs2 = stat($ARGV[1]); 
printf "%d\n", $attrs2[9] - $attrs1[9];' $1 $2 

age=`get_age ${1} ${2}` 
echo age is $age seconds 
=============================== 
$ touch test1; sleep 10; touch test2; ksh .//lt.sh test1 test2 
age is 10 seconds

www.unixbabuforum.inIf you're using bash, the ls command has a time format option that allows you to make such computations. In your case, the following command will yield the (signed) age difference in seconds between the two files: 
expr `ls -l --time-style +%s b.log|tr -s " "|cut -d" " -f6` - `ls -l --time-style +%s a.log|tr -s " "|cut -d" " -f6` 
If your ls does not have the option, you will have to do it the hard way



0 comments:

Post a Comment

 
Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM