>> 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.
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to