2010-05-10 912 views

回答

3
"excluding the lines that don't have a character at the beginning" 

是相同

"including the lines that have the character at the beginning" 

要得到所有以字符s開始,你可以做線:

grep '^s' filename 

例子:

[23:18:03][/tmp]$ cat test 
stack 
overflow 
testing 
sample 
[23:21:37][/tmp]$ grep '^s' test # To list lines beginning with s 
stack 
sample 
+1

同樣,如果您有多個角色可能在開始您可以使用字符類: grep'^ [adf]'文件名 將匹配任何以a,d或f開頭的行。 – 2010-05-10 06:26:53

+0

如果我不知道在開始的哪些字符?有沒有辦法指定一個空白空間? – neuromancer 2010-05-10 07:06:08

+2

要僅列出那些沒有前導空格的行,請使用:'grep'^ [^]'test' – codaddict 2010-05-10 07:08:06

相關問題