#!/bin/bash S="Pineapple" if [[ "${S}" == *apple* ]]; then echo "Yes" else echo "No" fi
S="Pineapple" if [[ "`echo ${S}|grep apple `" != "" ]]; then echo "Yes"else echo "No"fi
S="Pineapple"if [[ ! -z $(echo ${S} | grep apple) ]]; then echo "Yes"else echo "No"fi
This is helpful
Hi,And new way.S="Pineapple"if [ "${S}" =~ "apple" ]; thenecho "Yes"elseecho "No"fiIt's work fine for linux.by pepsi
Works on Mac as well. Thanks.
how do you check if a file contains a string without using sed or awk or grep command?
while read linedo if [[ "${line}" == *apple* ]]; then echo "YES" break fidone < /path/to/yourfile.txt
S="Pineapple"
ReplyDeleteif [[ "`echo ${S}|grep apple `" != "" ]]; then
echo "Yes"
else
echo "No"
fi
S="Pineapple"
Deleteif [[ ! -z $(echo ${S} | grep apple) ]]; then
echo "Yes"
else
echo "No"
fi
This is helpful
DeleteHi,
ReplyDeleteAnd new way.
S="Pineapple"
if [ "${S}" =~ "apple" ]; then
echo "Yes"
else
echo "No"
fi
It's work fine for linux.
by pepsi
Works on Mac as well. Thanks.
Deletehow do you check if a file contains a string without using sed or awk or grep command?
ReplyDeletewhile read line
Deletedo
if [[ "${line}" == *apple* ]]; then
echo "YES"
break
fi
done < /path/to/yourfile.txt