Computing.Net > Forums > Unix > passing awk variables to shell

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

passing awk variables to shell

Reply to Message Icon

Name: VimFuego
Date: December 19, 2003 at 07:32:07 Pacific
OS: FreeBSD
CPU/Ram: P3 64M
Comment:

i've seen a solution for this with single line awk, but what if i want to extract the variables from the awk END section back to the shell? any ideas?

thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: December 19, 2003 at 08:29:51 Pacific
Reply:

Hi:

I'm not certain, but I think you're aware of command substituion. Here's an example:

x=`echo ""|nawk ' { print "Hi" }
END { print "Ending" } '`

this if you use ksh:

x=$(echo ""|nawk ' { print "Hi" }
END { print "Ending" } ')

Now, if you want to get just the END output into a variable without the other statement you can redirect to a file and read the file.

x=$(echo ""|nawk ' { print "Hi" }
END { print "Ending" > "ending.txt"} ')

y=$(cat ending.txt)
echo "y is $y"

You can append to the ending.txt file using >>.

Regards,

Nails


0

Response Number 2
Name: VimFuego
Date: December 23, 2003 at 07:29:09 Pacific
Reply:

great. i was wondering if there was syntax similar to the " -v awkvar="$shellvar" " method for inputting shell variableds, but the file output solution works perfect for what i want. thanks.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: passing awk variables to shell

can I pass an awk variable to the s www.computing.net/answers/unix/can-i-pass-an-awk-variable-to-the-s/7251.html

Passing awk variables to wrapper www.computing.net/answers/unix/passing-awk-variables-to-wrapper/5669.html

Pass environment variables to sed www.computing.net/answers/unix/pass-environment-variables-to-sed/7387.html