CSV file date processing in shell script -


i have csv log file 2 columns, each having time stamp request(1 st column) , response(2nd column).

here sample data:

2013-07-11 08:39:08.748,2013-07-11 08:39:08.748 2013-07-11 08:39:08.826,2013-07-11 08:39:08.826 2013-07-11 08:39:08.860,2013-07-11 08:39:08.860 2013-07-11 08:39:08.919,2013-07-11 08:39:08.919 2013-07-11 08:39:08.941,2013-07-11 08:39:08.941 2013-07-11 08:39:09.390,2013-07-11 08:39:09.390 2013-07-11 08:39:09.594,2013-07-11 08:39:09.594 2013-07-11 08:39:09.619,2013-07-11 08:39:09.619 2013-07-11 08:39:09.787,2013-07-11 08:39:09.787 2013-07-11 08:39:10.006,2013-07-11 08:39:10.006 2013-07-11 08:39:10.017,2013-07-11 08:39:10.017 2013-07-11 08:39:10.088,2013-07-11 08:39:10.088 2013-07-11 08:39:10.214,2013-07-11 08:39:10.214 

i want calculate average of difference of 2 columns (response - request) complete file. file can contain million entries in day.

i looking way shell script. please help.

thanks fedorqui, tried script:

while read line;   d1=$(echo $line | cut -d, -f1);  d2=$(echo $line | cut -d, -f2);   ds1=$(date -d"$d1" "+%s");  ds2=$(date -d"$d2" "+%s");  echo "$ds2 - $ds1 = $(( $ds1 - $ds2))";  done < requestresponse.csv 

it giving me following results:

1373543260 - 1373543260 = 0 1373543260 - 1373543260 = 0 1373543260 - 1373543260 = 0 1373543260 - 1373543260 = 0 1373543260 - 1373543260 = 0 1373543260 - 1373543260 = 0 1373543260 - 1373543260 = 0 1373543261 - 1373543261 = 0 1373543262 - 1373543262 = 0 1373543262 - 1373543262 = 0 

i need difference in milliseconds.

i did in basic shell script nanoseconds:

while read line    d1=$(echo $line | cut -d, -f1)    d2=$(echo $line | cut -d, -f2)    ds1=$(date -d"$d1" "+%s.%n")    ds2=$(date -d"$d2" "+%s.%n")    diff=$(echo "$ds2 - $ds1" | bc)    printf "$ds2 - $ds1 = %.3f\n" $diff done < file 

test

$ while read line; d1=$(echo $line | cut -d, -f1); d2=$(echo $line | cut -d, -f2); ds1=$(date -d"$d1" "+%s.%n"); ds2=$(date -d"$d2" "+%s.%n"); diff=$(echo "$ds2 - $ds1" | bc); printf "$ds2 - $ds1 = %.3f\n" $diff; done < file 1373524748.748000000 - 1373524748.748000000 = 0.000 1373524748.826000000 - 1373524748.826000000 = 0.000 1373524748.860000000 - 1373524748.860000000 = 0.000 1373524748.919000000 - 1373524748.919000000 = 0.000 1373524748.941000000 - 1373524748.941000000 = 0.000 1373524749.390000000 - 1373524749.390000000 = 0.000 1373524749.594000000 - 1373524749.594000000 = 0.000 1373524749.619000000 - 1373524749.619000000 = 0.000 1373524749.787000000 - 1373524749.787000000 = 0.000 1373524750.006000000 - 1373524750.006000000 = 0.000 1373524750.017000000 - 1373524750.017000000 = 0.000 1373524750.088000000 - 1373524750.088000000 = 0.000 1373524750.214000000 - 1373524750.214000000 = 0.000 

Comments