Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Command substitution/backtick problem
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!!

Report this thread to moderator Post Follow-up to this message
Old Post
tylernt
11-16-04 11:50 PM


Re: Command substitution/backtick problem

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!!

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
11-16-04 11:50 PM


Re: Command substitution/backtick problem
tylernt@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

Report this thread to moderator Post Follow-up to this message
Old Post
Ulrich M. Schwarz
11-16-04 11:50 PM


Re: Command substitution/backtick problem
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?

$ 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

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
11-16-04 11:50 PM


Re: Command substitution/backtick problem
In <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

Report this thread to moderator Post Follow-up to this message
Old Post
William Park
11-16-04 11:50 PM


Re: Command substitution/backtick problem
Why 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.
>



Report this thread to moderator Post Follow-up to this message
Old Post
javier
11-18-04 01:55 AM


Re: Command substitution/backtick problem
Why 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.
>



Report this thread to moderator Post Follow-up to this message
Old Post
javier
11-21-04 08:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:04 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.