View Single Post
Old Sep 7th, 2004, 9:20 PM   #5
erebus
Programmer
 
erebus's Avatar
 
Join Date: Aug 2004
Location: /dev/null
Posts: 65
Rep Power: 5 erebus is on a distinguished road
Send a message via AIM to erebus
Actually, most newer implementations of awk (POSIX, Nawk, or Gawk) has the -v switch so you can interface awk and shell variables. Something like this should suffice:
awk -v name="$USER" '{ print name }'
Or you can use a built-in associative array that accepts a current environment variable name as its index, which is quite handy for working with the shell:
awk '{ print ENVIRON["USER"] }'
Another less efficient way would be to use the export command, though I won't give an example because I like the above methods, but it can be done.

For your problem, it's a little bit tricky. Maybe something like:
var=`awk '{ printf "%d", $1 }' filename`
Not sure if that's what you were looking for, but working with the above information will get you where you need to go. This will substitue anything in back-quotes with the output of the command sequence within the two, thus, saving what should have gone to stdout to a variable. Sorry I couldn't be of much help.
__________________
<span style='font-size:14pt;line-height:100%'><span style='color:red'>&quot;Political power grows out of the barrel of a gun&quot; - Mao Tse-Tung</span></span>
erebus is offline   Reply With Quote