如何判断某个文件是否存在某一字符串?

如何判断某个文件是否存在某一字符串?

想在if条件里判断,但用grep好像不行啊:
if [grep "keyword" targetfile.txt];      
$ if grep "your string" /your/file; then echo yes; else echo no; fi
## 或者
$ if grep -q "your string" /your/file; then echo yes; else echo no; fi      
复制内容到剪贴板
代码:
if: if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
    The if COMMANDS are executed.  If the exit status is zero, then the then
    COMMANDS are executed.  Otherwise, each of the elif COMMANDS are executed
    in turn, and if the exit status is zero, the corresponding then COMMANDS
    are executed and the if command completes.  Otherwise, the else COMMANDS
    are executed, if present.  The exit status is the exit status of the last
    command executed, or zero if no condition tested true.
      
[ x = y ] 也是 command !      
if [ "`cat targfile.txt|grep -c keyword`" != 0 ];then
    echo "have"
   else
    echo "havent"
fi      
if [ "`cat targfile.txt|grep -c keyword`" != 0 ];then
    echo "have"
   else
    echo "havent"
fi      
谢谢,受教了