首页 > 系统服务 > 详细

shell ——grep

时间:2015-09-29 20:36:23      阅读:264      评论:0      收藏:0      [点我收藏+]

grep -q 用于if 逻辑判断很好用。
-q 参数,本意是 Quiet; do not write anything to standard output.  Exit immediately with zero status if any match is found, even if an error was detected.   中文意思为,安静模式,不打印任何标准输出。如果有匹配的内容则立即返回状态值0。

小应用

# cat a.txt
nihao 
nihaooo
hello

#  if  grep -q hello a.txt ; then echo yes;else echo no; fi 
yes
# if grep -q word a.txt; then echo yes; else echo no; fi
no

 

  1. grep -q "abcdef" a.txt
  2. if [ $? == 0 ]; then#查找成功
  3.     echo xxoo
  4. else
  5.     echo ooxx
  6. fi

shell ——grep

原文:http://www.cnblogs.com/myyan/p/4847098.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!