I want to run a script in unix that will look for a specific pattern inside a passed argument. The argument is a single word, in all cases. I cannot use grep, as grep only works on searching through files. Is there a better unix command out there that can help me?
+4
A:
Grep can search though files, or it can work on stdin:
$ echo "this is a test" | grep is this is a test
atk
2010-10-08 02:50:28
+1
A:
Depending on what you're doing you may prefer to use bash pattern matching:
# Look for text in $word
if [[ $word == *text* ]]
then
echo "Match";
fi
or regular expressions:
# Check is $regex matches $word
if [[ $word =~ $regex ]]
then
echo "Match";
fi
Alexandre Jasmin
2010-10-08 03:00:48
+1
A:
you can use case/esac
as well. No need to call any external commands (for your case)
case "$argument" in
*text* ) echo "found";;
esac
ghostdog74
2010-10-08 03:05:55