shell根据关键字获取文件某一行的行号

cat -n 文件名|grep '关键字'|awk '{print $1}'

cat -n是获取行号,要是获取行内容,去掉-n就可以了。

猜你喜欢

转载自my.oschina.net/bobwei/blog/1823639