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

grep:排除以空白字符开头的行,grep,Grep,我有一个文本文件,其中有些行的开头有一个字符,有些行没有。我想将文本文件打印到屏幕上,不包括开头没有字符的行 我能和格雷普一起做这个吗 "excluding the lines that don't have a character at the beginning" 与 "including the lines that have the character at the beginning" 要获取以chars开头的所有行,可以执行以下操作: grep '^s' filename

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

我能和格雷普一起做这个吗

"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

类似地,如果有多个字符可能位于开头,则可以使用字符类:grep“^[adf]”文件名将匹配以a、d或f开头的任何行。如果我不知道哪些字符位于开头,该怎么办?有没有办法指定空格?要仅列出那些没有前导空格的行,您可以使用:
grep'^[^]'test