awk search if else

Hi,
I want to search for a particular string using awk and print "Found" or "Not Found" depending on the search.

On searching this forum i got this code but it is not working:

Something like this?

awk '/Reference_Data/{f=1;exit}END{print f?"Found":"Not Found"}' file
1 Like

Can you try as..

 
awk '{print $0~/Reference_Data/?"Found":"Not Found"}' file
or
awk '{print /Reference_Data/?"Found":"Not Found"}' file # not sure if this would work
 
1 Like
declare -i toggle=0
while read -r line
do
  case "$line" in
     *Reference_Data*) toggle=1;;
  esac
done < file
if [ $toggle -eq 0 ] ;then
   echo "Not found"
else
   echo "Found"
fi
1 Like

thanks for replies, but i am still getting same error.

Use nawk or /usr/xpg4/bin/awk on Solaris.

1 Like

Thanks.. now working fine..