[dmtsai@study ~]$
grep
-
n '^[^a
-
zA
-
Z]' regular_express.txt
1:
"
Open Source" is a good mechanism to develop programs.
21:
#
I am VBird
#
指令也可以是:
grep
-
n '^[^[:alpha:]]' regular_express.txt
注意到了吧?
那个
^
符号,在字符集合符号
(
括号
[])
之内与之外是不同的!
在
[]
内代表『反向选择』,
在
[]
之外则代表定位在行首的意义
!要分清楚喔!
反过来思考,那如果我想要找出来,行尾½束
为小数点
(.)
的那一行,该如何处理:
[dmtsai@study ~]$
grep
-
n '
\
.$' regular_express.txt
1:"Open Source" is a good mechanism to develop programs
.
2:apple is my favorite food
.
3:Football game is not use feet only
.
4:this dress doesn't fit me
.
10:motorcycle is cheap than car
.
11:This window is clear
.
12:the symbol '*' is represented as start
.
15:You are the best is mean you are the no. 1
.
16:The world <Happy> is the same with "gl
ad"
.
17:I like dog
.
18:google is the best tools for search keyword
.
20:go! go! Let's go
.
特别注意到,因为小数点具有其他意义
(
底下会½绍
)
,所以必须要使用跳脱字符
(\)
来加以½除其特殊
意义!
不过,你或许会觉得奇怪,但是第
5~9
行最后面也是
.
啊~怎么无法打印出来?
这里就牵
涉到
Windows
平台的软件对于断行字符的判断问题了!我们使用
cat -A
½第五行拿出来看,
你会
发现:
[dmtsai@study ~]$
cat
-
An regular_express.txt | head
-
n 10 | tail
-
n 6
5 However, this dress is about $ 3183 dollars.
^M
$
6 GNU is free air not free beer.
^M
$
7 Her hair is very beauty.
^M
$
8 I can't finish the test.
^M
$
9 Oh! The soup taste good.
^M
$
10 motorcycle is cheap than car.$
我们在
第九章内谈到过断行字符
在
Linux
与
Windows
上的差异,
在上面的表格中我们可以发现
5~9
行为
Windows
的断行字符
(^M$)
,而正常的
Linux
应该½有第
10
行显示的那样
($)
。所以
啰,那个
.
自然就不是½½在
$
之前喔!也就捉不到
5~9
行了!这样可以了½
^
与
$
的意义吗?
好了,先不要看底下的½答,自己想一想,那么如果我想要找出来,哪一行是『空白行』,
也就是
说,该行并没有输入任何数据,该如何搜寻?
[dmtsai@study ~]$
grep
-
n '^$' regular_express.txt