Quoting Swamp: Saving an awk command in a shell variable 
Author Message
 Quoting Swamp: Saving an awk command in a shell variable

Because apparently I have a {*filter*}ic streak, I'm needing to do the
following (Bourne shell pseudocode with whitespace added):

    saved_command = awk '{print $3}'

and then later

    do some stuff | $saved_command

to end up executing

    do some stuff | awk '{print $3}'

The reason for this is that the saved_command might not use field number
3, or might not be awk, or might actually be a "grep foo | awk" etc etc.
There are several conditional assignments to saved_command.

I've tried multiple levels of quoting and backslashing and I just
can't get the magic combination.  I've used awk for trivial and
slightly-complicated things in the past -- nothing heavy -- but I've
never tried saving an awk {} program as shell text and calling it later.

Would any quoting god care to lend a hand?



Tue, 15 Apr 2003 08:24:09 GMT  
 Quoting Swamp: Saving an awk command in a shell variable


...
Quote:
>    saved_command = awk '{print $3}'
...
>    do some stuff | $saved_command
...
>The reason for this is that the saved_command might not use field
>number 3, or might not be awk, or might actually be a "grep foo |
>awk" etc etc. There are several conditional assignments to
>saved_command.

...

Which shell? The first shell command above gives an error under bash.
Have you tried

saved_command="awk '{ print \$3 }'"

Sent via Deja.com http://www.deja.com/
Before you buy.



Tue, 15 Apr 2003 12:14:59 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing command line variables to AWK in shell script

2. awk variables --> shell variables

3. Substituting single quotes from Perl via shell using awk and gsub

4. Can I execute shell commands from awk?

5. shell commands within awk script

6. Invoking shell command from within awk

7. executing a shell command within AWK

8. AWK-Script to set a shell variable (Win32) ?

9. setting shell variables with results from awk

10. Exporting awk variables to the UNIX shell

11. help for newbie: way to get the value of an awk variable in a shell script

12. how to use a shell variable in awk for pattern matching

 

 
Powered by phpBB® Forum Software