awk "date" and "system" command

Hello experts!
I need your help please

I have a file.txt of which I want to extract 3rd and 4th columns with date with the form e.g.:

2016-11-25 03:14:50

and pass them to "date" command, but also append the 9th column in a file as well.

So I want to execute

 date -d '2016-11-25 03:14:50'  +"%s" 

but also get additionally the 9th field in a file.

So far I have tried with

 awk '{print "date -d \x27"  $3, $4 "\x27  +\x22%s\x22", $9}' file.txt |sh 

but I get:

 date: extra operand �9nth field content' 

I also did experiment with "system" command trying:

 awk '{system("date -d \x27"  $3, $4 "\x27  +\x22%s\x22")}'  file.txt

but I get:

2 is invalid as number of arguments for system

Thank you in advance for your help

M 2.9 FRANCE

Try this:

awk '{print "date -d \x27"  $3, $4 "\x27  +\x22%s" OFS $9 "\x22"}' file.txt | sh

or this

awk '{system("date -d \x27"  $3 " " $4 "\x27  +\x22%s " $9 "\x22")}'  file.txt

Or if you have GNU awk you can convert date within awk:

awk '{
   gsub("[-/]", " ", $3)
   gsub("[:]", " ", $4)
   print strftime("%s", mktime($3 " " $4)),$9 
}' file.txt
1 Like

Thank you very much! it worked!

M 3.0 OKLAHOMA