It is currently Thu, 20 Jan 2022 10:33:20 GMT



 
Author Message
 porting a script with nawk to awk
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.



 Sat, 09 Sep 2006 04:02:48 GMT   
 porting a script with nawk to awk

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.



 Sat, 09 Sep 2006 04:13:30 GMT   
 porting a script with nawk to awk

True.  Also, Gawk has 'ENVIRON' array.

--
William Park, Open Geometry Consulting, <opengeome...@yahoo.ca>
Linux solution for data processing and document management.



 Sat, 09 Sep 2006 04:41:52 GMT   
 porting a script with nawk to awk
On Mon, 22 Mar 2004 20:02:48 GMT, Joe Philip
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!]



 Sat, 09 Sep 2006 07:00:58 GMT   
 porting a script with nawk to awk
"Ed Morton" <mor...@lsupcaemnt.com> wrote, on Mon, 22 Mar 2004:

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 <nos...@gclare.org.uk>



 Sat, 09 Sep 2006 21:58:27 GMT   
 porting a script with nawk to awk

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



 Sun, 10 Sep 2006 01:34:58 GMT   
 porting a script with nawk to awk

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



 Sun, 10 Sep 2006 01:34:58 GMT   
 porting a script with nawk to awk

    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.

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



 Sun, 10 Sep 2006 01:41:06 GMT   
 porting a script with nawk to awk
"Chris F.A. Johnson" <c.fa.john...@rogers.com> wrote in message <news:c3psrh$2b37nb$2@ID-210011.news.uni-berlin.de>...

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



 Sun, 10 Sep 2006 21:16:33 GMT   
 porting a script with nawk to awk
2004-03-24, 05:16(-08), Stu:
[...]
[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

--
Stphane                      ["Stephane.Chazelas" at "free.fr"]



 Sun, 10 Sep 2006 22:11:17 GMT   
 
   [ 10 post ] 

Similar Threads

1. ns 6.21b ns6install script should use nawk vs awk

2. Passing values generated in awk/nawk back to script

3. Shell script question (awk || nawk)...

4. search on variable passed to awk /nawk

5. nawk and awk

6. awk vs. nawk

7. cat algore | nawk -f stripgarbage.awk > gwbush

8. AWK/NAWK/GAWK/MAWK

9. gawk, nawk, and awk


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software