The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 01-05-2009
mirusko mirusko is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 14
Awk, shell variables

Hello, I've been trying to figure out how to use variables inside the AWK command and use it back in the korn shell sript.

in my script I have lots of awk commands like this

grep Listen /etc/ssh/sshd_config | \
awk '{ if ($2 == "22" ) print "OK";
else print "not OK"
}'

I need to add a counter to count how many issues/problems I have, something like

x=0

grep Listen /etc/ssh/sshd_config | \
awk '{ if ($2 == "22" )
print "OK";
else
print "not OK"
x++
}'

# ... more of awk commands ...

echo x;

unfortunatelly x "inside" the awk command is different/local to awk command ... is there a way to do thi/

Thank you,
K.