Linux查找文件中的字符串命令

 

grep -nr 'archermind'

 

-r, --recursive
Read all files under each directory, recursively, following symbolic links
only if they are on the command line. This is equivalent to the -d
recurse option.

 

-n, --line-number
Prefix each line of output with the 1-based line number within its input
file. (-n is specified by POSIX.)

 

grep介绍   (1)grep 的一般格式为 grep [options] 基本正则表达式 [文件] 
      字符串参数最好采用是双引号括,一是以防被误解为shell命令,二是可以用来查找多个单词组成的字符串 
      -c:只输出匹配行的记数 
      -i:不区分大小写(只适用于单个字符) 
      -h:查询多个文件时不显示文件名 
      -H:只显示文件名 
      -l:查询多文件时只输出包含匹配字符的文件名 
      -n:只显示匹配行及其行号 
      -s:不显示不存在或无匹配文本的错误信息。 
      -v:显示不包含匹配文本的所有行。 
  (2)举例说明: 
      grep ^[^210] myfile 匹配myfile中以非2、1、0开头的行 
      grep "[5-8][6-9][0-3]" myfile 匹配myfile中第一位为5|6|7|8,第二位6|7|8|9,第三位为0|1|2|3的三个字符的行 
      grep "4\{2,4\}" myfile 匹配myfile中含有44,444或4444的行 
      grep "\?" myfile匹配myfile中含有任意字符的行 
  (3)grep命令类名 
      [[:upper:]]   表示[A-Z] 
      [[:alnum:]]   表示[0-9a-zA-Z] 
      [[:lower:]]   表示[a-z] 
      [[:space:]]   表示空格或者tab键 
      [[:digit:]]   表示[0-9] 
      [[:alpha:]]   表示[a-zA-Z] 
    如:grep "5[[:digit:]][[:digit:]]" myfile 匹配myfile中含有5开头接下去两位都是数字的行。

转载于:https://www.cnblogs.com/luolizhi/p/5889465.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值