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?
|
|
0
|
|
|
|
Reply
|
bengt.tornq (7)
|
6/29/2010 2:02:50 PM |
|
In article <488e1dbf-aeb2-493e-b7c7-a130c20f0d22@y11g2000yqm.googlegroups.com>,
Bengt T <bengt.tornq@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.
|
|
0
|
|
|
|
Reply
|
gazelle
|
6/29/2010 2:44:22 PM
|
|
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
|
|
0
|
|
|
|
Reply
|
Thomas
|
6/29/2010 2:59:46 PM
|
|
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
|
|
0
|
|
|
|
Reply
|
Hermann
|
6/29/2010 5:12:18 PM
|
|
On 29 Juni, 19:12, Hermann Peifer <pei...@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
|
|
0
|
|
|
|
Reply
|
Bengt
|
6/30/2010 6:18:58 PM
|
|
|
4 Replies
732 Views
(page loaded in 0.087 seconds)
|