sed 与正则表达式组合应用(一)
2011-12-07 09:08
288 查看
sed 与正则表达式组合格式
sed ‘/正则表达式/sed命令‘
1、区分大小写
$ echo "This is a test" |sed -n '/this/p'
$ echo "this is a test" |sed -n '/this/p'
this is a test
2、模式匹配的文本要大于或等于 表达式集合
$ echo "The books are expensive" | sed -n '/book/p'
The books are expensive
$ echo "The book are expensive" | sed -n '/books/p'
$ echo "The books are expensive" | sed -n '/book/p'
The books are expensive
$ echo "This is line number 1" | sed -n '/number 1/p'
This is line number 1
3、识别空格
$ cat >data1
This is a normal line of text.
This is a line with too many spaces.
$ sed -n '/ /p' data1
This is a line with too many spaces.
4、支持定位符^ $
$ echo "The book store" | sed -n '/^book/p'
$ echo "book store" | sed -n '/^book/p'
book store
$ echo "This ^ is a test" | sed -n '/s ^/p'
This ^ is a test
$ cat data4
this is a test of using both anchors
I said this is a test
this is a test
I'm sure this is a test
$ sed -n '/^$/d' data4
$ sed '/^$/d' data4
this is a test of using both anchors
I said this is a test
this is a test
I'm sure this is a test
5、支持. 字符代替任何字符
$ cat >data6
This is a test of a line
The cat is sleeping.
That is a very nice cat.
This test is at line four.
at ten o'clock we'll go home.
$ sed -n '/.at/p' data6
The cat is sleeping.
That is a very nice cat.
This test is at line four.
sed ‘/正则表达式/sed命令‘
1、区分大小写
$ echo "This is a test" |sed -n '/this/p'
$ echo "this is a test" |sed -n '/this/p'
this is a test
2、模式匹配的文本要大于或等于 表达式集合
$ echo "The books are expensive" | sed -n '/book/p'
The books are expensive
$ echo "The book are expensive" | sed -n '/books/p'
$ echo "The books are expensive" | sed -n '/book/p'
The books are expensive
$ echo "This is line number 1" | sed -n '/number 1/p'
This is line number 1
3、识别空格
$ cat >data1
This is a normal line of text.
This is a line with too many spaces.
$ sed -n '/ /p' data1
This is a line with too many spaces.
4、支持定位符^ $
$ echo "The book store" | sed -n '/^book/p'
$ echo "book store" | sed -n '/^book/p'
book store
$ echo "This ^ is a test" | sed -n '/s ^/p'
This ^ is a test
$ cat data4
this is a test of using both anchors
I said this is a test
this is a test
I'm sure this is a test
$ sed -n '/^$/d' data4
$ sed '/^$/d' data4
this is a test of using both anchors
I said this is a test
this is a test
I'm sure this is a test
5、支持. 字符代替任何字符
$ cat >data6
This is a test of a line
The cat is sleeping.
That is a very nice cat.
This test is at line four.
at ten o'clock we'll go home.
$ sed -n '/.at/p' data6
The cat is sleeping.
That is a very nice cat.
This test is at line four.
相关文章推荐
- [收藏] 正则表达式的入门与应用,1~4篇!grep/sed/perl/awk
- [收藏] 正则表达式的入门与应用,1~4篇!grep/sed/perl/awk
- [收藏] 正则表达式的入门与应用,1~4篇!grep/sed/perl/awk
- sed配合正则表达式应用案例
- sed配合正则表达式应用
- awk-grep-sed简单使用总结(正则表达式的应用)
- grep,sed,awk与简单正则表达式应用
- [收藏] 正则表达式的入门与应用,1~4篇!grep/sed/perl/awk
- Linux下正则表达式以及几种工具:grep,sed,awk,cut,sort,uniq的简单应用
- Shell基础(四):正则表达式、cut、awk、sed命令
- 正则表达式的应用
- 正则表达式学习笔记005--脱字符和美元符的认识与应用
- sed 正则表达式sed不明了的地方
- 第7章 sed、gawk介绍与正则表达式-----------(sed编辑器简单使用)
- iOS中系统自带正则表达式的应用以及一些常用的正则表达式
- iOS正则表达式的应用
- Shell正则表达式与grep、sed、awk的特点
- Linux系统编程(19)——正则表达式在sed和awk中的使用
- 正则表达式在objectiv-c中的简单应用
- Java正则表达式应用总结