simple while loop call for help
by Drosera_capensis from LinuxQuestions.org on (#57ZJS)
Hello everyone,
I have made a little while loop to process a file line per line using a list of matching expressions.
And I wished to print "0" if there were no matches.
But I guess the if( $2 >= 0 ) part is not appropriate for no match. Would anyone know how to do it?
Code:while read f ;
do
awk '/'$f'/ {if( $2 >= 0 ) {print $2} else {print "0"}}' file ;
done < list


I have made a little while loop to process a file line per line using a list of matching expressions.
And I wished to print "0" if there were no matches.
But I guess the if( $2 >= 0 ) part is not appropriate for no match. Would anyone know how to do it?
Code:while read f ;
do
awk '/'$f'/ {if( $2 >= 0 ) {print $2} else {print "0"}}' file ;
done < list