Code Comments
Programming Forum and web based access to our favorite programming groups.I want to feed awk a line, and have it spit out a reformatted line --
converting a UNIX epoch date to human-readable format. So, input to
awk would be
one two 1082567969 four five
and the output from awk would be
one two Wed Apr 21 18:19:29 MDT 2004 four five
So, the command that I would like to run in bash (ksh is not
available) is:
tail -f filename | awk '{print $1, $2, `date -d "1970-01-01 $3 sec"`,
$4, $5}'
But, obviously, this does not work. I have tried all sorts of
combinations of backticks and backslashes, quotes, double quotes,
tried the system() command, everything. But I can't figure it out.
Can anyone help me? Even if the solution uses something other than awk
or date -d?
Thanks!!
Post Follow-up to this message
tylernt wrote:
> I want to feed awk a line, and have it spit out a reformatted line --
> converting a UNIX epoch date to human-readable format. So, input to
> awk would be
>
> one two 1082567969 four five
>
> and the output from awk would be
>
> one two Wed Apr 21 18:19:29 MDT 2004 four five
>
> So, the command that I would like to run in bash (ksh is not
> available) is:
>
> tail -f filename | awk '{print $1, $2, `date -d "1970-01-01 $3 sec"`,
> $4, $5}'
>
> But, obviously, this does not work. I have tried all sorts of
> combinations of backticks and backslashes, quotes, double quotes,
> tried the system() command, everything. But I can't figure it out.
>
> Can anyone help me? Even if the solution uses something other than awk
> or date -d?
Use "system()" to call external commands. For this particular job,
you're probably better off sticking with a shell script than wrapping it
in awk.
Ed.
> Thanks!!
Post Follow-up to this messagetylernt@gmail.com (tylernt) writes:
> I want to feed awk a line, and have it spit out a reformatted line --
> converting a UNIX epoch date to human-readable format. So, input to
> awk would be
>
> one two 1082567969 four five
>
> and the output from awk would be
>
> one two Wed Apr 21 18:19:29 MDT 2004 four five
echo "o t 1082567969 f f" | awk '$3=strftime("%a %b %d %H:%M:%S %Z %Y", $3)'
But I'm sure Kenny will shave off another dozen chars off that ;-)
Ulrich
--
"I am now forced to postulate a Heraldic-Taste-based anti-spam
blocklist for top-level-domains. I can just imagine the SMTP
reject codes... 550: go away - your flag looks like a fish."
-- Tanuki
Post Follow-up to this messagetylernt wrote:
> I want to feed awk a line, and have it spit out a reformatted line --
> converting a UNIX epoch date to human-readable format. So, input to
> awk would be
>
> one two 1082567969 four five
>
> and the output from awk would be
>
> one two Wed Apr 21 18:19:29 MDT 2004 four five
>
> So, the command that I would like to run in bash (ksh is not
> available) is:
>
> tail -f filename | awk '{print $1, $2, `date -d "1970-01-01 $3 sec"`,
> $4, $5}'
>
> But, obviously, this does not work. I have tried all sorts of
> combinations of backticks and backslashes, quotes, double quotes,
> tried the system() command, everything. But I can't figure it out.
>
> Can anyone help me? Even if the solution uses something other than awk
> or date -d?
$ echo one two 1082567969 four five | perl -pe's/(\b\d{8,10}\b)/localtime $1
/ge'
one two Wed Apr 21 10:19:29 2004 four five
John
--
use Perl;
program
fulfillment
Post Follow-up to this messageIn <comp.unix.shell> tylernt <tylernt@gmail.com> wrote:
> I want to feed awk a line, and have it spit out a reformatted line --
> converting a UNIX epoch date to human-readable format. So, input to
> awk would be
>
> one two 1082567969 four five
>
> and the output from awk would be
>
> one two Wed Apr 21 18:19:29 MDT 2004 four five
>
> So, the command that I would like to run in bash (ksh is not
> available) is:
>
> tail -f filename | awk '{print $1, $2, `date -d "1970-01-01 $3 sec"`,
> $4, $5}'
>
> But, obviously, this does not work. I have tried all sorts of
> combinations of backticks and backslashes, quotes, double quotes,
> tried the system() command, everything. But I can't figure it out.
>
> Can anyone help me? Even if the solution uses something other than awk
> or date -d?
Why Awk? Shell is just fine.
tail -f filename | while read a b sec c d; do
echo $a $b `date -d "1970-01-01 $sec sec"` $c $d
done
--
William Park <opengeometry@yahoo.ca>
Open Geometry Consulting, Toronto, Canada
Post Follow-up to this messageWhy not? It happens to be the simplest solution for everybody (unless you have a simpler one in awk) BTW nobody said awk is off the topic. "Kenny McCormack" <gazelle@yin.interaccess.com> wrote in message news:cmo88n$5gf$1@yin.interaccess.com... > In article <2v2sfqF2hpo1qU1@uni-berlin.de>, > William Park <opengeometry@yahoo.ca> wrote: > > Why shell? AWK is on-topic here. >
Post Follow-up to this messageWhy not? It happens to be the simplest solution for everybody (unless you have a simpler one in awk) BTW nobody said awk is off the topic. "Kenny McCormack" <gazelle@yin.interaccess.com> wrote in message news:cmo88n$5gf$1@yin.interaccess.com... > In article <2v2sfqF2hpo1qU1@uni-berlin.de>, > William Park <opengeometry@yahoo.ca> wrote: > > Why shell? AWK is on-topic here. >
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.