Piping to UNIX date function -
to format date timestamp, i'd use eg date -d "2012-05-06 12:12" "+%s". if have file date per line how like:
cat file.txt | date "+%s" # not work i following:
cat file.txt | while read line; `date -d "$line" "+%s"`; done; but utterly ugly...
other solution converting date-time timestamp (in format yyyy-mm-dd hh:mm:ss) acceptable well.
edit: real life example bit more complex, let me elaborate:
`some command produces complex lines` | grep only-speicif-lines | awk '{ print $5 | (i want pass date here timestamp in end)}'
this makes it:
while read mydate date -d "$mydate" "+%s" done < file note solution
cat file.txt | while read line; `date -d "$line" "+%s"`; done; is not way read file line per line. need to
while read line; `date -d "$line" "+%s"`; done < file.txt ^^^^^^^^^^ test
$ cat 2012-05-06 12:12 2012-05-06 12:13 $ while read mydate; date -d "$mydate" "+%s"; done < 1336299120 1336299180 update
from comment:
edit: real life example bit more complex, let me elaborate:
`some command produces complex lines` | grep only-speicif-lines | awk '{ print $5 | (i want pass date hereto timestamp in end)}'
this can make it:
xargs -i date -d "{}" "+%s" test
$ cat | grep 2 | xargs -i date -d "{}" "+%s" # grep here silly example 1336299120 1336299180
Comments
Post a Comment