2

I have file with below data

# date format in file is (YYYY MM DD HH MM SS)
 file_create_date       file_execute_date       file_name     
"2017 10 10 12 24 30" , "2017 10 11 09 23 00" , LTE--cNum--T201710110923--W101114450--CHGLSMR01LEMS1--sam--4.0.csv.gz

i want output like this

 file_create_date       file_execute_date       difference          file_name     
"2017 10 10 12 20 30" , "2017 10 11 13 31 59" ,  "1 Day 01:11:29, "LTE--cNum--T201710110923--W101114450--CHGLSMR01LEMS1--sam--4.0.csv.gz"

my script is :

awk -F',' '{print $1 "," , $2  , (mktime($2)-mktime($1))/86400 " Day",$3}' Filename

But mktime() returns -1.

fedorqui
  • 275,237
  • 103
  • 548
  • 598

1 Answers1

6

You're passing mktime a string containing double quotes and blank chars at the start and end. Remove those.

$ echo '"2017 10 10 12 24 30" , "2017 10 11 09 23 00"'
"2017 10 10 12 24 30" , "2017 10 11 09 23 00"

$ echo '"2017 10 10 12 24 30" , "2017 10 11 09 23 00"' | awk -F',' '{print mktime($1)}'
-1

$ echo '"2017 10 10 12 24 30" , "2017 10 11 09 23 00"' | awk -F',' '{gsub(/\s*"\s*/,""); print mktime($1)}'
1507656270
Ed Morton
  • 188,023
  • 17
  • 78
  • 185