Date: Wed, 20 Feb 2013 04:35:18 +0200 From: "bw.mail.lists" <bw.mail.lists@gmail.com> To: freebsd-questions@freebsd.org Subject: Re: convert date and time to epoch in awk Message-ID: <51243666.5000408@gmail.com> In-Reply-To: <00df01ce0efe$c98f8030$5cae8090$@freebsd.org> References: <CAHM0YgvadWLRUNvyQzTj0b=YkfZAyzRRCTEyjByqXM9yXsynhg@mail.gmail.com> <00df01ce0efe$c98f8030$5cae8090$@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
>> So, is there a way to compare two dates in FreeBSD's awk or convert a date >> to epoch? Or some other fast way to select the last 10 minutes from a log >> file? An example would be appreciated, if possible. > > > Converting a date to an epoch is easy with date(1) (note: awk can make a system > call and read back the stdout into a variable). > > For example, if I want to convert the date: > > Fri 01 Feb 2013 > > into an epoch using: > > date -j -f "%a %d %b %Y" "Fri 01 Feb 2013" +%s > > The output of which is the following epoch: > > 1359763497 > > Doing this all from awk: > > echo "Fri 01 Feb 2013" | awk ' > { > mydate = $0 > "date -j -f \"%a %d %b %Y\" \"" mydate "\" +%s" | getline myepoch > print mydate " = " myepoch > }' > > Hope this helps. > It does, exactly what I was looking for, many thanks.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?51243666.5000408>