17个案例带你3分钟搞定Linux正则表达式

与世无争的帅哥 提交于 2019-11-28 23:57:59

正则表达式是一种字符模式,用于在查找过程中匹配制定的字符。

元字符通常在Linux中分为两类:

Shell元字符,由Linux Shell进行解析;

正则表达式元字符,由vi/grep/sed/awk等文本处理工具进行解析;

正则表达式一般以文本行进行处理,在进行下面实例之前,先为grep命令设置--color参数:

 

$ alias grep='grep --color=auto'

这样每次过滤出来的字符串都会带色彩了。

在开始之前还需要做一件事情,就是创建一个测试用的re-file文件,内容如下:

 

$ cat re-file  I had a lovely time on our little picnic.  Lovers were all around us. It is springtime. Oh  love, how much I adore you. Do you know  the extent of my love? Oh, by the way, I think  I lost my gloves somewhere out in that field of  clover. Did you see them?  I can only hope love.  is forever. I live for you. It's hard to get back in the  groove.

文件内容摘录自<<UNIX/SHELL范例精解第四版>>

 

$ cat linux.txt  Linux is a good   god assdxw bcvnbvbjk  greatttttt  wexcvxc  operaaaating  dhfghfvx  gooodfs awrerdxxhkl  gdsystem awxxxx  glad  good

正则表达式元字符

特殊的元字符

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!