行首行尾字符^$

来源:互联网 发布:ei数据库高级检索 编辑:程序博客网 时间:2024/04/30 13:04
grep -n ‘^a’ test.txt 
在test.txt中查询a在行首的行 
grep -n ‘^[a-z]’ test.txt 
在test.txt中查询小写字母在行首的行 
grep -n ‘^[^a-zA-Z]’ test.txt 
在test.txt中查询不是字母在行首的行 
注意:^ 符号,在括号[]内代表反向选择,在 [] 外则表示定位在行首 
grep -n‘\.$’test.txt 

在test.txt中查询以.结尾的行

注意:.有其他含义,这里加\接触其所具有的其他含义

grep -n '^$'test.txt 

在test.txt中查询空白行
原创粉丝点击