grep:排除以空白字符开头的行

时间:2010-05-10 06:15:19

标签: grep

我有一个文本文件,其中一些行在开头有一个字符而有些行没有。我想将文本文件打印到屏幕,不包括开头没有字符的行。

我可以用grep吗?

1 个答案:

答案 0 :(得分:3)

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

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

要获取以char 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