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
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?
|