我有一个文本文件,其中一些行在开头有一个字符而有些行没有。我想将文本文件打印到屏幕,不包括开头没有字符的行。
我可以用grep吗?
答案 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