app*_*nic 10 grep shell-script text-processing
有什么方法可以找出文本文档的哪一行是匹配模式的单词,例如 grep 或其他东西。谢谢。
hee*_*ayl 18
是的,可以-n
选择grep
.
来自man grep
:
-n, --line-number
Prefix each line of output with the 1-based line number within its input file.
Run Code Online (Sandbox Code Playgroud)
例如,如果您有一个名为的文件file.txt
:
this is
foo test
and this is
bar test
Run Code Online (Sandbox Code Playgroud)
现在输出grep -n "test" file.txt
:
$ grep -n "test" file.txt
2:foo test
4:bar test
Run Code Online (Sandbox Code Playgroud)
这里 2 和 4 表示找到模式的行号。