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 -->
  #3 (permalink)  
Old 02-11-2009
fedora fedora is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 94
I reliazed that problem, but it seems I can not fix the problem, here is the modified script

awk '{ for (i=0; i<=NF; i++)
if($i~/user/)
{a=$i}
else
{a="no"}
{ continue}
{print a}
}' /tmp/test

and the output change to

no
user_d
user_a
no
no

which is not correct at all.


Quote:
Originally Posted by joeyg View Post
I think it is because you are always printing a value. So, you are not over-writing 'a' ni the instance of the 4th line, so when you print the variable, you are getting the last stored value of 'a'.
Perhaps as the first line ater your else, do a
Code:
a=""

to blank out the last 'a' value?