http://blog.itpub.net/27181165/viewspace-1061688/
在linux中通常會使用shell結合正則表達式來過濾字符,本文將以一個簡單的例子來說明+,*,[:space:]的一些用法
+ 匹配1個或多個字符
* 匹配0個或多個字符
[:space:] 匹配空白字符,包括空格,tab
文件file是含有多個空格和tab的幾行字符,下面將以file文件為例做幾個簡單的實驗
[root@node1 ~]# cat file
5
5
5
5
5
5
刪除空格
[root@node1 ~]# sed 's/ *//g' file
5
5
5
5
5
5
[root@node1 ~]#
刪除空格
[root@node1 ~]# sed 's/ +//g' file
5
5
5
5
5
5
[root@node1 ~]#
沒有起作用
[root@node1 ~]# sed 's/ \+//g' file
5
5
5
5
5
5
[root@node1 ~]#
+轉義以后可以刪除空格
[root@node1 ~]# sed 's/[[:space:]]//g' file
5
5
5
5
5
5
[root@node1 ~]#
刪除所有的空白字符,包括tab
