On Wed, 2007-03-07 at 17:06 -0500, Manish Popli wrote: > I need to write a shell script to compare row in a file. and show the > difference. > > Like in row 2nd it showing 21:30:49 > > And in row 3rd it showing 19:25:21
Incompletely specified. How are the rows separated? What is the meaning of the fields? Hours:Minutes:Seconds for 24h time? Do we have to worry about roll-over? Is sanity-checking of file format, and input values required? Why a shell script? For a trivial implementation in bash, assuming HH:MM::SS, disregarding most details and error-checking, save the following nine lines to a file, say diff.sh, #!/bin/bash while read f1 f2 f3 do set `IFS=:; echo $f2` h2=$1; m2=$2; s2=$3 set `IFS=:; echo $f3` h3=$1; m3=$2; s3=$3 echo "Difference is $(($h2*3600+$m2*60+$s2-$h3*3600-$m3*60-$s3))" done < $1 Do, chmod +x diff.sh and, invoke as ./diff.sh test.txt where test.txt is the name of the file containing your records. Regards, Gora _______________________________________________ ilugd mailinglist -- [email protected] http://frodo.hserus.net/mailman/listinfo/ilugd Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi http://www.mail-archive.com/[email protected]/
