美文网首页
系统符号

系统符号

作者: 张新雨有点胖噢 | 来源:发表于2019-07-22 19:51 被阅读0次

系统基础正则

正则符号主要是为三剑客grep sed awk命令做辅助作用
基础正则 basic regular expression 简称 BRE

  1. ^符号 代表以什么开头2.
[root@zin ~]# cat oldboy.txt 
 am oldboy teacher!
        I teach linux.
        
        I like badminton ball ,billiard ball and chinese chess!
        my blog is http://oldboy.blog.51cto.com
        our site is http://www.etiantian.org
        my qq num is 49000448.
        
        not 4900000448.
        my god ,i am not oldbey,but OLDBOY!
[root@zin ~]# grep '^ a' oldboy.txt 
 am oldboy teacher!
  1. $符号代表以什么结尾
[root@zin ~]# grep 'm$' oldboy.txt 
my blog is http://oldboy.blog.51cto.com
  1. ^$ 代表空行
  2. . 匹配一个且只有一个字符 和通配*号差不太多
    . 符号拥有三个特特性
    1.会按照行进行匹配
    2.会匹配信息的贪婪特性(默认不加匹配项会一个一个的匹配文件所有内容)
    3.利用grep -o可以查看匹配信息过程
[root@zin ~]# grep '.d' oldboy.txt 
 am oldboy teacher!
        I like badminton ball ,billiard ball and chinese chess!
        my blog is http://oldboy.blog.51cto.com
        my god ,i am not oldbey,but OLDBOY!
  1. *符号 匹配前面一个字符连续出现 0次或者多次
    因为*号是匹配0或者多次 所以会将所有内容显示出来 因为没有的会默认出现0次
[root@zin ~]# grep "d*" oldboy.txt 
 am oldboy teacher!
        I teach linux.
        
        I like badminton ball ,billiard ball and chinese chess!
        my blog is http://oldboy.blog.51cto.com
        our site is http://www.etiantian.org
        my qq num is 49000448.
        
        not 4900000448.
        my god ,i am not oldbey,but OLDBOY!
ZZ
  1. .*符号 匹配所有内容
[root@zin ~]# grep ".*" oldboy.txt 
 am oldboy teacher!
        I teach linux.
        
        I like badminton ball ,billiard ball and chinese chess!
        my blog is http://oldboy.blog.51cto.com
        our site is http://www.etiantian.org
        my qq num is 49000448.
        
        not 4900000448.
        my god ,i am not oldbey,but OLDBOY!
ZZ
  1. []方括号符号 符号里的内容会分别过滤
[root@zin ~]# grep '[as]' oldboy.txt 
 am oldboy teacher!
        I teach linux.
        I like badminton ball ,billiard ball and chinese chess!
        my blog is http://oldboy.blog.51cto.com
        our site is http://www.etiantian.org
        my qq num is 49000448.
        my god ,i am not oldbey,but OLDBOY!
  1. [^] 匹配取反
[root@zin ~]# grep '[^0-9]' oldboy.txt 
 am oldboy teacher!
        I teach linux.
        I like badminton ball ,billiard ball and chinese chess!
        our site is http://www.etiantian.org
        my god ,i am not oldbey,but OLDBOY!
匹配的是数值0-9 所有把所有有数字
所有所有有数值的都没显示 

扩展正则

扩展正则: extended regular expression 缩写 ERE
扩展正则三剑客中awk可以无条件使用
其中grep需要变形成egrep或者加上参数 grep -E才可使用
sed需要加参数-r才可以使用 sed -r

  1. +符号 匹配前一个字符出现1次或者多次
    因为是1~多次 所有不会像*号一样出现显示没有匹配项也出现的问题
[root@zin ~]# egrep "0+" oldboy.txt 
  our site is 0 http://www.etiantian.org
  my qq num is 49000448.
  1. | 匹配多个不同的字符串信息
[root@zin ~]# grep -E 'not|and' oldboy.txt 
      I like badminton ball ,billiard ball and chinese chess!
      not 4900000448.
      my god ,i am not oldbey,but OLDBOY!
  1. ()小括号符号 两个作用
    1.将多个信息进行整合过滤
    2.实现后项引用前向进行替换
例
[root@zin ~]# echo "123456"|sed -r 's#([0-9]+)#<\1>#g'
将前向() 利用\1 引用过来赋予新的值或任务
<123456>
  1. {} 匹配括号前一个字符出现的次数
    1.xxx{n,m} 匹配xxx出现n次到m次
    2.xxx{n}匹配xxx出现n次
    3.xxx{n,}匹配xxx最少n次 上不限次数
    4.xxx{,m}匹配xxx最少0次 上限m次
  2. ? 前一个字符连续出现0次或一次
[root@zin ~]# grep -E '?u' oldboy.txt 
        I teach linux.
        our site is http://www.etiantian.org
        my qq num is 49000448.
        my god ,i am not oldbey,but OLDBOY!

相关文章

  • 人工科学卡片4---任何智力系统都是符号系统

    术语卡:符号系统 印象:符号系统包含着一组称为符号的存在物,存在物结构依附于物质模式,符号系统具备对符号结构发生作...

  • 符号系统

    学习算法之前,先介绍统一一下衡量算法复杂度的符号系统,尤其时间复杂度: O (<=),f(n) = O(g(n))...

  • day 17 操作系统正则符号/grep

    系统通配符号: 系统正则符号:grep sed awk 系统正则: BRE( basic regular e...

  • 2019-07-23

    day18 操作系统正则符号/grep 1.系统通配符号2.系统正则符号 知识回顾: 1.系统文件属性(文件类型 ...

  • 06系统正则符号

    系统符号作用简化操作,进行匹配 系统特殊符号基础符号$ 用于取出变量的内容;用于取出指定列的信息(awk);表...

  • Day17操作系统正则符号(2)

    课程知识梳理复习1) 系统基础符号基础符号系列: # $ ! |引号符号系列: "" '' `` 没有引号定向...

  • LaTeX教学2.3 符号

    2.3 符号 在写作论文时要用到标点符号, 数学符号和单位符号等许多符号. 在LaTeX系统中可以把各种符号分为以...

  • 第一章 品牌就是符号

    品牌要么始于符号,要么成为符号。 宣传是使用符号系统来达到特定目的的活动。 符号定义商品,商品符号定义人。 商品蕴...

  • 7.2符号方法与符号系统

    7.1传统语言学问题 7.1.1符号的价值、能指、所指 7.1.2符号的任意性与线性 7.2符号方法与符号系统 本...

  • 什么是Lambda演算?

    1.什么是解释系统 宇宙的表象,即,宇宙中的符号。 符号背后有意义。 为了表达符号背后的意义,需要解释系统,来将符...

网友评论

      本文标题:系统符号

      本文链接:https://www.haomeiwen.com/subject/piialctx.html