Prev: CONTROLLED DEMOLITION INC explosive-charge placement technician Tom ?Sullivan 911 TESTIMONIAL Video
Next: CONTROLLED DEMOLITION INC explosive-charge placement technician Tom Sullivan 911 TESTIMONIAL Video
From: Bengt T on 29 Jun 2010 10:02 The command <date -u -d "2010/06/28 18:06:11" +%s> creates epoch time for the given date and time. I wish to create epoch times for a file according to the following example: 2009/10/02 18:02:36 2009/12/03 07:45:55 2010/05/16 13:03:56 etc... ....by a command similar to <gawk -v x=$( date -u -d "$1 $2" +%s ) '{print $1" "$2" "x}' input_file_name > output_file_name. This does however not work as I have expected. The "$1"-information is used but the "$2"-information is ignored. Can anyone advice how a proper command syntax, using bot $1- and $2- information, should be written?
From: Kenny McCormack on 29 Jun 2010 10:44 In article <488e1dbf-aeb2-493e-b7c7-a130c20f0d22(a)y11g2000yqm.googlegroups.com>, Bengt T <bengt.tornq(a)gmail.com> wrote: >The command <date -u -d "2010/06/28 18:06:11" +%s> creates epoch time >for the given date and time. > >I wish to create epoch times for a file according to the following >example: > >2009/10/02 18:02:36 >2009/12/03 07:45:55 >2010/05/16 13:03:56 >etc... The best answer to your question is: man gawk<enter>/mktime<enter> In the meantime, you might want to try: {printf "%s ",$0;gsub(/[/:]/," ");t = mktime($0);print t,strftime("%c",t)} -- > No, I haven't, that's why I'm asking questions. If you won't help me, > why don't you just go find your lost manhood elsewhere. CLC in a nutshell.
From: Thomas 'PointedEars' Lahn on 29 Jun 2010 10:59 Bengt T wrote: > The command <date -u -d "2010/06/28 18:06:11" +%s> creates epoch time > for the given date and time. > > I wish to create epoch times for a file according to the following > example: > > 2009/10/02 18:02:36 > 2009/12/03 07:45:55 > 2010/05/16 13:03:56 > etc... > > ...by a command similar to <gawk -v x=$( date -u -d "$1 $2" +%s ) > '{print $1" "$2" "x}' input_file_name > output_file_name. This does > however not work as I have expected. The "$1"-information is used but > the "$2"-information is ignored. The information is not ignored; you are simply defining the variable only once. > Can anyone advice how a proper command syntax, using bot $1- and $2- > information, should be written? I think if it could be done in gawk it would be unreadable (CMIIW). This works if the last line ends with newline: while read d t do date -ud "$d $t" "+$d $t %s" done < input_file_name > output_file_name PointedEars
From: Hermann Peifer on 29 Jun 2010 13:12 On 29/06/2010 16:02, Bengt T wrote: > The command<date -u -d "2010/06/28 18:06:11" +%s> creates epoch time > for the given date and time. > > I wish to create epoch times for a file according to the following > example: > > 2009/10/02 18:02:36 > 2009/12/03 07:45:55 > 2010/05/16 13:03:56 > etc... > Here a gawk alternative. Potentially unreadable, as someone stated. gawk '{d=$0; gsub(/[/:]/, " ", d); print $0, mktime(d)}' yourdata 2009/10/02 18:02:36 1254499356 2009/12/03 07:45:55 1259822755 2010/05/16 13:03:56 1274007836 1970/01/01 00:00:00 -3600 Gawk assumes the time to be in the local timezone. However, you could set to your time zone to UTC, in order to get the correct epoch time: TZ=UTC gawk '{d=$0; gsub(/[/:]/, " ", d); print $0, mktime(d)}' yourdata 2009/10/02 18:02:36 1254506556 2009/12/03 07:45:55 1259826355 2010/05/16 13:03:56 1274015036 1970/01/01 00:00:00 0 Hermann
From: Bengt T on 30 Jun 2010 14:18
On 29 Juni, 19:12, Hermann Peifer <pei...(a)gmx.eu> wrote: > On 29/06/2010 16:02, Bengt T wrote: > > > The command<date -u -d "2010/06/28 18:06:11" +%s> creates epoch time > > for the given date and time. > > > I wish to create epoch times for a file according to the following > > example: > > > 2009/10/02 18:02:36 > > 2009/12/03 07:45:55 > > 2010/05/16 13:03:56 > > etc... > > Here a gawk alternative. Potentially unreadable, as someone stated. > > gawk '{d=$0; gsub(/[/:]/, " ", d); print $0, mktime(d)}' yourdata > 2009/10/02 18:02:36 1254499356 > 2009/12/03 07:45:55 1259822755 > 2010/05/16 13:03:56 1274007836 > 1970/01/01 00:00:00 -3600 > > Gawk assumes the time to be in the local timezone. However, you could > set to your time zone to UTC, in order to get the correct epoch time: > > TZ=UTC gawk '{d=$0; gsub(/[/:]/, " ", d); print $0, mktime(d)}' yourdata > 2009/10/02 18:02:36 1254506556 > 2009/12/03 07:45:55 1259826355 > 2010/05/16 13:03:56 1274015036 > 1970/01/01 00:00:00 0 > > Hermann Thank you all for your responses! They solved my issue. /Bengt T |