How to find if a substring exists in a string or not in Shell/Unix scripting

Shell @ Freshers.in

This will be a common use case when we need to check some substring in a log or some file.  You can achieved by using the below scripts. In the below we need to search the keyword “freshers” in the string given

string='freshers.in/tags/python'
if [[ $string == *"freshers"* ]]; then
  echo "Substring found"
else
  echo "NOT FOUND"
fi
Author: user

Leave a Reply