$ cat file {null};2013-11-26;Text & Device;Location;/file/path/to/;Tuesday, November 26 12:17 PM;1;1385845647 $ gawk 'BEGIN{FS=OFS=";"} {gsub(/-/," ",$2); $2=mktime($2" 0 0 0")}1' file {null};1385445600;Text & Device;Location;/file/path/to/;Tuesday, November 26 12:17 PM;1;1385845647
Here, as usual, convert the date from any format in seconds from the era using the current format as an example and with comments to show the conversion process step by step:
$ cat tst.awk function cvttime(t, a) { split(t,a,/[,: ]+/)
I am sure you can change this for the current problem.
Alternatively, if you don't have gawk, you can write the cvttime () function as a string (borrowing @sputnik date ):
$ cat tst2.awk function cvttime(t, cmd,secs) { cmd = "date -d \"" t "\" '+%s'" cmd | getline secs close(cmd) return secs } BEGIN { mdt ="Tuesday, November 26 10:17 PM" secs = cvttime(mdt) dt = strftime("%Y-%m-%d %H:%M:%S",secs) print mdt ORS "\t-> " secs ORS "\t\t-> " dt } $ $ awk -f tst2.awk Tuesday, November 26 10:17 PM -> 1385525820 -> 2013-11-26 22:17:00
I left srtftime () just to show that secs is correct - replace date as you like.
For the non-gawk version, you just need to figure out how to get the year in the input month / date / time so that date understands whether this mask suits you - it should not be difficult.
source share