awk vs echo
Chris L. Fouts
dprclf at ARCO.COM
Tue Feb 12 05:56:43 AEST 1991
In message <9102111145.aa01900 at VGR.BRL.MIL>; "Peter Jaspers-Fayer" writes:
> I guess that even after a year of trying, I do not understand the way
> the shell (csh) passes things to it's children, viz:
>
> This is an excerpt from a longer awk command, and I'm stuck:
>
> This works
> awk '{ print "'$user': " $0}'
> as does
> awk '{ print "'`hostname`': " $0}'
> But not
> awk '{ print "'`date`': " $0}' (Spaces(?) Colons(?))
> Even tho
> echo '{ print "'`date`': " $0}' works OK, and if I CUT&PASTE
> the result of the echo into another awk '', something like:
>
> awk '{ print "Mon Feb 11 11:35:32 EST 1991: " $0}' IT WORKS!
>
> Why are the last and 2nd-last awks different? Anyone please?
The first awk winds up as
awk '{ print "'Mon Feb 11 11:35:32 EST 1991': " $0}'
which has the awk program spread across multiple arguments as highlighted
below:
awk '{ print "'Mon Feb 11 11:35:32 EST 1991': " $0}'
^^^^^^^^^^^^^^ ^^^ ^^ ^^^^^^^^ ^^^ ^^^^^^^^^^^^^ = 6 args
whereas
awk '{ print "Mon Feb 11 11:35:32 EST 1991: " $0}'
has the awk program in only 1 argument.
To accomplish what you want (get ready for yet more quotes), try:
awk '{ print "'"`date`"': " $0}'
^ ^
| |
+------+----These quotes prevent the spaces in the
date output from splitting up the
argument.
My head starts hurting if I look at this too long....
--
Chris L. Fouts
Email: dprclf at phobos
Ext: 3850
"Fate is the path of least action."
-- Kim Stanley Robinson in "A Short, Sharp Knock"
"Every day, I sit in traffic and consider my fate...."
More information about the Comp.sys.sgi
mailing list