9.10 显示搜索结果在文件中的行号
-n
grep
命令能够显示包含正在搜索内容的那一行,但并不能指出在文件中的哪个位置能够找到那行信息。要找到行号,可以利用-n
(或--line-number
)选项。
$ grep -n pain *
fiery inferno in space.txt:56:watch the paint peel,
three_no_more_forever.txt:19:all alone and in pain
the speed of morning.txt:66:of a Chinese painting.
8 hour a day.txt:78:nice paint job too
ghost pain.txt:32:Subject: ghost pain
现在知道每个pain
字符串实例所在行的行号了,几乎在任何文本编辑器中都可以直接跳转到指定行。真是太棒了!