Linux / UNIX Tech Support Forum
This is a discussion on How do i find difference between 2 file dates in shell scriptting within the Shell scripting forums, part of the Development/Scripting category; HI I need script which can find difference between two dates Example: TS1="Feb 25 20:36:55 IST 2009" TS2="Feb 26 02:36:55 ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
HI
I need script which can find difference between two dates Example: TS1="Feb 25 20:36:55 IST 2009" TS2="Feb 26 02:36:55 IST 2009" I should get output as 06:00:00 TS1="Feb 25 20:36:55 IST 2009" TS2="Feb 26 22:36:55 IST 2009" Output should be 1Day:02:00:00 Please need help to resolve this I had tried script but not working properly #!/bin/bash TS1="Feb 25 20:36:55 IST 2009" TS2="Feb 26 02:36:55 IST 2009" echo TS1 is $TS1 ; echo TS2 is $TS2 ; Y1=`echo $TS1 | awk -F " " '{ print $NF }'` echo Year1 is $Y1 ; Y2=`echo $TS2 | awk -F " " '{ print $NF }'` echo Year is $Y2 ; M1=`echo $TS1 | awk -F " " '{ print $1 }'` echo "Month1 is $M1" ; M2=`echo $TS2 | awk -F " " '{ print $1 }'` echo "Month2 is $M2 "; Day1=`echo $TS1 | awk -F " " '{ print $2 }'` echo "Day1 is $Day1 "; Day2=`echo $TS2 | awk -F " " '{ print $2 }'` echo "Day2 is $Day2 "; HR1=`echo $TS1 | awk -F " " '{ print $3 }' | awk -F ":" '{ print $1 }' ` echo HR1 is $HR1 HR2=`echo $TS2 | awk -F " " '{ print $3 }' | awk -F ":" '{ print $1 }' ` echo HR2 is $HR2 M1=`echo $TS1 | awk -F " " '{ print $3 }' | awk -F ":" '{ print $2 }' ` echo Minute1 $M1 M2=`echo $TS2 | awk -F " " '{ print $3 }' | awk -F ":" '{ print $2 }' ` echo Minute1 $M2 S1=`echo $TS1 | awk -F " " '{ print $3 }' | awk -F ":" '{ print $3 }' ` echo Second1 is $S1 S2=`echo $TS2 | awk -F " " '{ print $3 }' | awk -F ":" '{ print $3 }' ` echo Second2 is $S2 if [ $S1 -lt $S2 ] then Second_Diff=`expr $S2 - $S1` else S2=`expr $S2 + 60` M2=`expr $M2 - 1` Second_Diff=`expr $S2 - $S1` fi echo Second_Diff is $Second_Diff #### End of seconds ### Start for Minutes comparison### if [ $M1 -lt $M2 ] then Minute_Diff=`expr $M2 - $M1` else M2=`expr $M2 + 60` Minute_Diff=`expr $M2 - $M1` HR2=`expr $HR2 - 1` fi echo Minute Diff $Minute_Diff ### End of Minutes ### Compare Hour comparision#### if [ $HR1 -lt $HR2 ] then Hour_Diff=`expr $HR2 - $HR1 + 24` else HR2=`expr $HR2Hr + 24` Hour_Diff=`expr $HR2 - $HR1` fi echo "Second Diff is $Second_Diff" echo "Minute Diff is $Minute_Diff" echo "HR_Diff is $Hour_Diff"; printf "Total time taken for build is %2.2d:%2.2d:%2.2d\n" $Hour_Diff $Minute_Diff $Second_Diff Appreciate your help to resolve this Thanks Bharathi |
| Sponsored Links | ||
|
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Find Unix Linux File / Directory by date And Then Copy / Move File | asim.mcp | CentOS / RHEL / Fedora | 1 | 10-08-2008 03:30 AM |
| shell script to search specific file from txt file inside zip file and extract it | aasif.shaikh | Shell scripting | 2 | 31-05-2008 06:44 PM |
| writing a shell script to find out my shell name | jaymob123 | Shell scripting | 1 | 08-10-2007 12:36 AM |
| Difference between ext2 and ext3 Linux file system | nixcraft | Getting started tutorials | 0 | 18-05-2007 01:43 AM |
| Difference between Linux Swap partition & Swap file | hrishikesh | Linux software | 9 | 16-03-2007 02:08 AM |