It is currently Tue, 07 Dec 2021 03:32:31 GMT



 
Author Message
 SUMMARY: using sh vars in awk calls.
greetings all!

Ok, thanks to all who replied, and since I got a couple "me toos",
heres the deal:

Problem:
        in a /bin/sh script, need to pass a regular sh variable
        to the awk call, but the proper syntax is not-readily
        discernable.

Example:
        given sh vars $fred, call awk using fred, like so:

        wilma=`cat $filea | awk '{if($1==fred){print("match")}}'`

Solution:
        (1), escape out the sh variable by using single quotes.

         rhart...@thestepchild.esd.sgi.com (Robert Hartman) says:

         Kenneth Herron <kher...@ms.uky.edu> agrees with a slightly
        different syntax of

        (2), the other possible way is to declare awk a variable after
        the end of the awk script (in the man pages, but I cant find it)
        like so:

        d...@swbatl.sbc.com (David Neill-OKCy Mktg 405-278-4007) suggests

        and an...@coat.com (Andy Behrens) explains:

I've only tried the single quote method, and it works fine.  Some of
this is supposed to be dependent on your version of awk.  dont ask,
i dont know.

Thanks for all the info!

--gaspo.

BTW, to the dude who thought my sig was "long and obnoxious", you wouldnt
like my hair either!

/----------------------------------------------------------------------------\
| Scott "gaspo" Gasparian  --  System Administrator |"Do you go every Sunday?|
| Dept. Informatik, Eidg. Techn. Hochschule, Zurich | sounds to me like YOU  |
| ETH-Zentrum,  CH-8092  Zurich.  T# 01-01-254-7205 | are the {*filter*}ed one." |
| gas...@inf.ethz.ch | "Good friends we've had, or good friends we've lost,  |
| ..!ethz-inf!gaspar | along the way.In this proud land,you can't forget your|
| ga...@scri.fsu.edu | past,so dry your tears I say. No woman, No cry." -BMW |
\----------------------------------------------------------------------------/



 Tue, 21 Sep 1993 15:42:32 GMT   
 
   [ 1 post ] 

Similar Threads

1. using /bin/sh vars in awk

2. sh vars in awk scripts??

3. sh script using awk, argument issue?

4. Using awk and sh variables

5. using a c program to call a sh script

6. environment vars in sh script

7. sh: read vars from file

8. Length of sh or ksh environmental vars

9. Maintaining white space in vars (/bin/sh)

10. trying to pupulate vars from ls and awk


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