当前位置: 技术问答>linux和unix
怎样用grep搜索空白符开头的行.
来源: 互联网 发布时间:2016-04-05
本文导语: 想搜索以双引号开头的,或者几个空白符之后,再以双引号开头的,行,如下列的第1,2,5行. ================================================================================ [root@redhat ch17]# cat tt.txt "helo "this is this is line one. this is line...
想搜索以双引号开头的,或者几个空白符之后,再以双引号开头的,行,如下列的第1,2,5行.
================================================================================
[root@redhat ch17]# cat tt.txt
"helo
"this is
this is line one.
this is line two.
"tjos
:Wq
this is line one.
:w
[root@redhat ch17]# egrep '^s*"' tt.txt
"this is
[root@redhat ch17]#
================================================================================
以上即为实验的结果,按说应该打印出,1,2,5行才对呀?
请各位想想办法,这个正则表达式应该如何写?
================================================================================
[root@redhat ch17]# cat tt.txt
"helo
"this is
this is line one.
this is line two.
"tjos
:Wq
this is line one.
:w
[root@redhat ch17]# egrep '^s*"' tt.txt
"this is
[root@redhat ch17]#
================================================================================
以上即为实验的结果,按说应该打印出,1,2,5行才对呀?
请各位想想办法,这个正则表达式应该如何写?
|
你这个写法应该没什么问题,但有的系统的egrep不支持s,比如SuSE的系统就不支持,而redhat则支持。
你可以写成这样试一试:
egrep '^[ t]*"' tt.txt
中括号中一个是空格一个是tab
你可以写成这样试一试:
egrep '^[ t]*"' tt.txt
中括号中一个是空格一个是tab