|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Awk: How to get an awk variable out to the shell, using system() ?
I am reasonably capable with awk and its quirks, but not with shell weirdness. This has to be Bourne Shell for portability reasons. I have an awk program that is working just fine; it handles multiple input streams and produces several reports, based on the request (-v Variables). In addition to processing the stream, and producing the required report in the stream (so that it can be re-directed, etc), I write certain errors to a separate file. Now I need to enhance the program, to write to a specific filename (constructed per execution, no problem), and to sort the contents. I used the Site Search but nothing similar came up, due to the hundreds of badly formed thread titles. The generic question may be as simple as the thread title. This code snippet contains the seed of the problem, in simple form. The last two lines of code is a statement of intent; obviously it does not work as is.
Alternate approaches are welcome, as long as it does not result in a major code change. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
You need to place the variable outside the double quotes, for example try: Code:
system( "sort " ERR_FILE_TMP " >> " ERR_FILE ) |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
That was so simple ! Thanks.
But I do not see how that is "outside the double quotes". For the benefit of the understanding of others, that is "concatenate the string before submitting it to system()". And my concern about informing the shell re awk vars, is a non-issue. |
|
#4
|
||||
|
||||
|
You're welcome. What I meant was, in your original code you had ERR_FILE_TMP and FILE_TMP inside the double quotes, so they would be interpreted by awk as a literal string instead of a variable. So yes, the way to procede then is to create the string to be passed to system() by concatenation of string parts and variables...
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to use shell variable in awk? | thibodc | Shell Programming and Scripting | 8 | 04-11-2012 02:23 AM |
| assign awk's variable to shell script's variable? | tiger2000 | Shell Programming and Scripting | 4 | 04-13-2010 03:53 PM |
| shell function, system, awk | jkl_jkl | Shell Programming and Scripting | 5 | 06-02-2008 08:46 AM |
| shell variable in awk | cskumar | Shell Programming and Scripting | 12 | 08-20-2007 08:41 AM |
| can I pass awk variable to system command? | zhynxn | Shell Programming and Scripting | 2 | 07-05-2006 11:11 AM |
|
|