2010-05-10 51 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

相关问题