tag:blogger.com,1999:blog-2174891197290154044.post2977993749468966234..comments2024-02-18T08:15:20.893-08:00Comments on My Tech Notes: Shell Script: Check if a string contains a substringWXLhttp://www.blogger.com/profile/18374533961873126421noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-2174891197290154044.post-21656889798662867112018-01-08T22:49:04.073-08:002018-01-08T22:49:04.073-08:00This is helpfulThis is helpfulAnonymoushttps://www.blogger.com/profile/15127811330341951230noreply@blogger.comtag:blogger.com,1999:blog-2174891197290154044.post-54258231889011260862013-01-22T14:41:38.964-08:002013-01-22T14:41:38.964-08:00while read line
do
if [[ "${line}" == ...while read line<br />do<br /> if [[ "${line}" == *apple* ]]; then<br /> echo "YES"<br /> break<br /> fi<br />done < /path/to/yourfile.txtWXLhttps://www.blogger.com/profile/18374533961873126421noreply@blogger.comtag:blogger.com,1999:blog-2174891197290154044.post-75673660158895005112013-01-21T18:44:53.091-08:002013-01-21T18:44:53.091-08:00how do you check if a file contains a string witho...how do you check if a file contains a string without using sed or awk or grep command?Anonymoushttps://www.blogger.com/profile/03073090681233969223noreply@blogger.comtag:blogger.com,1999:blog-2174891197290154044.post-58321071323001608092012-10-30T07:16:04.332-07:002012-10-30T07:16:04.332-07:00S="Pineapple"
if [[ ! -z $(echo ${S} | ...S="Pineapple"<br /><br />if [[ ! -z $(echo ${S} | grep apple) ]]; then<br /> echo "Yes"<br />else<br /> echo "No"<br />fiWXLhttps://www.blogger.com/profile/18374533961873126421noreply@blogger.comtag:blogger.com,1999:blog-2174891197290154044.post-57300732469109317962012-10-30T07:13:14.485-07:002012-10-30T07:13:14.485-07:00Works on Mac as well. Thanks.Works on Mac as well. Thanks.WXLhttps://www.blogger.com/profile/18374533961873126421noreply@blogger.comtag:blogger.com,1999:blog-2174891197290154044.post-1036154203418011032012-10-30T04:20:54.731-07:002012-10-30T04:20:54.731-07:00Hi,
And new way.
S="Pineapple"
if [ &q...Hi,<br />And new way.<br /><br />S="Pineapple"<br /><br />if [ "${S}" =~ "apple" ]; then<br />echo "Yes"<br />else<br />echo "No"<br />fi<br /><br />It's work fine for linux.<br /><br />by pepsiAnonymoushttps://www.blogger.com/profile/12879197740747694849noreply@blogger.comtag:blogger.com,1999:blog-2174891197290154044.post-35896833312388779892012-10-30T04:00:20.345-07:002012-10-30T04:00:20.345-07:00S="Pineapple"
if [[ "`echo ${S}|g...S="Pineapple"<br /> <br />if [[ "`echo ${S}|grep apple `" != "" ]]; then<br /> echo "Yes"<br />else<br /> echo "No"<br />fi<br />Anonymoushttps://www.blogger.com/profile/12879197740747694849noreply@blogger.com