grep3

\(ab\)* 后向引用
\1,引用第一个括号内包涵的内容
\2,第二个
\3,第三个
$ grep  '\(l..e\).*\1' 12.txt  #前后一致
he loves me, lover
he like him , like her
he like her ,like me

前提回顾:
基本表达
.
[]
[^]

次数
*
\?   
\{m,n\} 
.*

铆钉
^
$
\b, \<
\b, \>

分组
\(\)
后向引用
\1,\2,\3

grep  -i
grep -o
grep --color
grep -v
grep -E :扩展正则表达式
grep -A:下面2行
grep -B:上面2行
grep -C:  上下各2行,context

$ grep -A 2 '\blove\b' 12.txt 
he like me , love me 
he like him , like her
he like her ,like me

grep -E :扩展正则表达式 or egrep

字符不一样:
?: 不用加\
+:匹配其前面的字符至少1次
{m,n}

$ grep -E 'l{1,5}..e.*' 12.txt 
he loves me, lover
he like me , love me 
he like him , like her
he like her ,like me


或者
|: or
$ grep -E 'H|he' 12.txt 
he loves me, lover
he like me , love me 
he like him , like her
he like her ,like me
He likes me 

$ grep -E '(H|h)e' 12.txt 
he loves me, lover
he like me , love me 
he like him , like her
he like her ,like me
He likes me 

$ grep -E '^[[:space:]]+' /boot/grub/grub.cfg 
  set have_grubenv=true
  load_env
   set default="${next_entry}"
   set next_entry=

$ egrep '\<([1-9]|[1-9][1-9])\>' /boot/grub/grub.cfg #找出1-99的整数


匹配元字符本身的意义
比如找. 需要加\.

友情阅读推荐:

生信技能树公益视频合辑:学习顺序是linux,r,软件安装,geo,小技巧,ngs组学!
B站链接:https://m.bilibili.com/space/338686099
YouTube链接:https://m.youtube.com/channel/UC67sImqK7V8tSWHMG8azIVA/playlists
生信工程师入门最佳指南:https://mp.weixin.qq.com/s/vaX4ttaLIa19MefD86WfUA
学徒培养:https://mp.weixin.qq.com/s/3jw3_PgZXYd7FomxEMxFmw

你可能感兴趣的:(grep3)