Which grep command will print only the lines that do not end with a / in the file foo?

A.

grep '/$' foo

B.

grep '/#' foo

C.

grep -v '/$' foo

D.

grep -v '/#' foo

题解

「grep」指令能以一行文字为单位,寻找该行文字中是否有符合的文字。grep 的正则表达式中,「^」代表一行的开头;「$」代表一行的结尾,「-v」参数表示输出相反的结果。因此若要取得结尾不为「/」的几行文字,应使用「/$」作为正则表达式,先取得结尾为「/」的文字,再加上「-v」参数得到相反的结果。所以选项 C 是正确答案。