|
Home > Archive > Unix Shell > March 2004 > porting a script with nawk to awk
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
porting a script with nawk to awk
|
|
| Joe Philip 2004-03-22, 3:35 pm |
| I have to move a script which uses nawk to another machine. This new machine
with HP-UX 11.11 does not have nawk. So, I want to replace the string which
has nawk with awk. For example,
I have the following line in the code
export PING_LIST=`echo $SERVER_LIST|nawk '{for (i=1; i<= NF; i=i+1) {if ($i
!~ ENVIRON["HOST"]) {print $i}}}'`
When I changed nawk to awk, somehow ENVIEON["HOST"] is not recognized.
Can someone help.
| |
| Ed Morton 2004-03-22, 3:35 pm |
|
Joe Philip wrote:
> I have to move a script which uses nawk to another machine. This new machine
> with HP-UX 11.11 does not have nawk. So, I want to replace the string which
> has nawk with awk. For example,
>
> I have the following line in the code
> export PING_LIST=`echo $SERVER_LIST|nawk '{for (i=1; i<= NF; i=i+1) {if ($i
> !~ ENVIRON["HOST"]) {print $i}}}'`
>
> When I changed nawk to awk, somehow ENVIEON["HOST"] is not recognized.
>
> Can someone help.
>
Can't you just install gawk on the new machine? It'll support ENVIRON
and, I suspect, be a much easier target for converting from nawk.
Ed.
| |
| William Park 2004-03-22, 4:34 pm |
| Ed Morton <morton@lsupcaemnt.com> wrote:
>
>
> Joe Philip wrote:
>
> Can't you just install gawk on the new machine? It'll support ENVIRON
> and, I suspect, be a much easier target for converting from nawk.
True. Also, Gawk has 'ENVIRON' array.
--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Linux solution for data processing and document management.
| |
| Bill Marcum 2004-03-22, 6:35 pm |
| On Mon, 22 Mar 2004 20:02:48 GMT, Joe Philip
<joe.philip@verizon.net> wrote:
> I have to move a script which uses nawk to another machine. This new machine
> with HP-UX 11.11 does not have nawk. So, I want to replace the string which
> has nawk with awk. For example,
>
> I have the following line in the code
> export PING_LIST=`echo $SERVER_LIST|nawk '{for (i=1; i<= NF; i=i+1) {if ($i
> !~ ENVIRON["HOST"]) {print $i}}}'`
>
> When I changed nawk to awk, somehow ENVIEON["HOST"] is not recognized.
>
> Can someone help.
>
If you can't install nawk or gawk,
export PING_LIST=`echo $SERVER_LIST|awk '{for (i=1; i<= NF; i=i+1) {if ($i
!~ HOST) {print $i}}}' HOST=$HOST`
--
Incrsease your earoning poswer and gaerner profwessional resspect.
Get the Un1iversity Dewgree you have already earned.
[from the prestigious, non-accredited university of Spam!]
| |
| Geoff Clare 2004-03-23, 9:38 am |
| "Ed Morton" <morton@lsupcaemnt.com> wrote, on Mon, 22 Mar 2004:
>
> Can't you just install gawk on the new machine? It'll support ENVIRON
> and, I suspect, be a much easier target for converting from nawk.
HP-UX awk supports ENVIRON, as do all POSIX-compliant awks. The problem
is most likely that there is no HOST environment variable set when the
script is run.
The POSIX awk definition was based on nawk, so there should be no
need to install gawk to run nawk scripts (with awk) on any POSIX
system.
--
Geoff Clare <nospam@gclare.org.uk>
| |
|
| Bill Marcum <bmarcum@iglou.com.urgent> wrote in message news:<aq74j1-jp3.ln1@don.localnet>...
> On Mon, 22 Mar 2004 20:02:48 GMT, Joe Philip
> <joe.philip@verizon.net> wrote:
> If you can't install nawk or gawk,
> export PING_LIST=`echo $SERVER_LIST|awk '{for (i=1; i<= NF; i=i+1) {if ($i
> !~ HOST) {print $i}}}' HOST=$HOST`
How about making your script portable
whence nawk > /dev/null
if [ $? -eq 0 ] ; then
AWK=nawk
else
whence awk > /dev/null
if [ $? -eq 0 ] ; then
AWK=awk
else
AWK=gawk
fi
fi
Use $AWK
| |
|
| Bill Marcum <bmarcum@iglou.com.urgent> wrote in message news:<aq74j1-jp3.ln1@don.localnet>...
> On Mon, 22 Mar 2004 20:02:48 GMT, Joe Philip
> <joe.philip@verizon.net> wrote:
> If you can't install nawk or gawk,
> export PING_LIST=`echo $SERVER_LIST|awk '{for (i=1; i<= NF; i=i+1) {if ($i
> !~ HOST) {print $i}}}' HOST=$HOST`
How about making your script portable
whence nawk > /dev/null
if [ $? -eq 0 ] ; then
AWK=nawk
else
whence awk > /dev/null
if [ $? -eq 0 ] ; then
AWK=awk
else
AWK=gawk
fi
fi
Use $AWK
| |
| Chris F.A. Johnson 2004-03-23, 1:37 pm |
| On Tue, 23 Mar 2004 at 17:34 GMT, Stu wrote:
> Bill Marcum <bmarcum@iglou.com.urgent> wrote in message news:<aq74j1-jp3.ln1@don.localnet>...
>
>
> How about making your script portable
>
> whence nawk > /dev/null
There's nothing portable about whence; it doesn't exist on many
systems; which is not much better.
> if [ $? -eq 0 ] ; then
> AWK=nawk
> else
> whence awk > /dev/null
> if [ $? -eq 0 ] ; then
> AWK=awk
> else
> AWK=gawk
gawk is far from universal; it should not be the default.
> fi
> fi
>
> Use $AWK
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
| |
|
| "Chris F.A. Johnson" <c.fa.johnson@rogers.com> wrote in message news:<c3psrh$2b37nb$2@ID-210011.news.uni-berlin.de>...[color=darkred]
> On Tue, 23 Mar 2004 at 17:34 GMT, Stu wrote:
>
> There's nothing portable about whence; it doesn't exist on many
> systems; which is not much better.
>
>
> gawk is far from universal; it should not be the default.
>
I think your mistaken.
check out the man page
typeset, whence - shell built-in functions to set/get attri-
butes and values for shell variables and functions
| |
| Stephane CHAZELAS 2004-03-24, 10:40 am |
| 2004-03-24, 05:16(-08), Stu:
[...]
[...][color=darkred]
> I think your mistaken.
>
> check out the man page
>
> typeset, whence - shell built-in functions to set/get attri-
> butes and values for shell variables and functions
[please don't full-quote when not necessary]
whence and typeset are ksh/zsh specific. typeset is also in bash
(an alias for declare) but the syntax and even the type of that
"builtin" is specific to each shell (in ksh and bash "typeset"
if more an assignment modifier than a builtin).
The POSIX commands are "type" and "command".
command -v nawk > /dev/null 2>&1
--
Stéphane ["Stephane.Chazelas" at "free.fr"]
|
|
|
|
|