Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variables from an awk program

Status
Not open for further replies.

COTLG

Technical User
Apr 15, 2003
107
US
Hi,

I used a variable within an awk program and need to use it in the rest of the script after the awk program ends. That is how can I pass a variable from an awk program (within a unix script)to the rest of the script. Please how do I do this?

Thanks,
Chike.
 
just a hint:

Code:
#!/bin/ksh

a=5

echo "before->[${a}]"
eval $(nawk -v a=${a} 'BEGIN { printf("a=%s\n",++a) }' < /dev/null)
echo "after->[${a}]"

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks vgersh99,

However I am new to awk and scripting in general. In short this is my first awk script. Kindly help me apply it to this script. I will appreciate it greatly:

#!/bin/ksh
count=1
df -k | awk '
{
$5 = substr($5,1,2)
$5 += 0
if($5 >= 70 && $5 <= 85)
{ Filesystem[count] = $6
$count += 1
print $5 "\t" Filesystem[count] "\t" $count "\n"
}
}')
echo "${count}"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top