开发者

grep: excluding lines that begin with a blank character

开发者_如何学JAVA

I have a text file where some lines have a character at the beginning and some lines don't. I want to print the text file to screen, excluding the lines that don't have a character at the beginning.

Can I do this with grep?


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

is same as

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

To get all the lines that start with char s you can do:

grep '^s' filename 

Example:

[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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜