[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AWK syntax
- To: misc_(_at_)_openbsd_(_dot_)_org
- Subject: Re: AWK syntax
- From: Hugo Villeneuve <harpagon_(_at_)_jwales_(_dot_)_EINTR_(_dot_)_net>
- Date: Wed, 21 Apr 2004 15:16:15 -0400
On Wed, Apr 21, 2004 at 06:22:23PM +0200, N.J. Reuvers wrote:
> My apologies, it does indeed work on Openbsd. I must have made a type
> error.
> However: echo $mystring | awk "{print \$$q}" does NOT work under HP Unix
> but DOES work on Openbsd.
If you don't use '' single quote, you are gonna have to use character
escapes which would be dependant on your shell.
To transfert values from the shell to the awk script, you would be
better using the "-v" switch.
like: awk -v q=$q '{ print $(q); }'
If you wanted to excludes tabs from the field separator, here I
can make it happen only with: -F "[ ]"
Now, I hope you know that simple awk command can be replaced by
bourne shell commands.
mystring="11 22 33"
q=2
set -- $mystrings
eval echo \$$q
And if you wanted to exclude tabs as a word separator, you can play
with IFS. (-- is so that set cannot be consufed by a regular option)
--
Hugo Villeneuve <hugo_(_at_)_EINTR_(_dot_)_net>
http://EINTR.net/
Visit your host, monkey.org