zoukankan      html  css  js  c++  java
  • 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开头接下去两位都是数字的行。

  • 相关阅读:
    Linux_WEB访问控制示例(使用IPADDR类型)
    基于多IP地址Web服务
    基于多端口的Web服务
    基于多主机的Web服务
    Linux_WEB服务基础概念
    Linux_配置认证访问FTP服务
    Linux_配置匿名访问FTP服务
    Linux_部署日志服务器
    Linux_日志管理理论概述
    微信小程序 radio 单选框
  • 原文地址:https://www.cnblogs.com/luolizhi/p/5889465.html
Copyright © 2011-2022 走看看