假如有test1.txt的格式如下图所示:

Linux:从文件中搜索关键字并显示行数(cat,grep函数)

有test2.txt的内容如下:

Linux:从文件中搜索关键字并显示行数(cat,grep函数)

现需将test2.txt含有的关键字的行搜索出来并显示行数

则可以用到命令:

cat test1.txt | grep -nf test2.txt #-n 表示找到匹配之后,输出匹配所在行数

  运行后,效果如下:

Linux:从文件中搜索关键字并显示行数(cat,grep函数)

36840733和36909134表示含有这两个关键字所在的行数。

相关文章:

  • 2021-07-13
  • 2022-01-03
  • 2021-11-27
  • 2022-12-23
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
猜你喜欢
  • 2022-01-21
  • 2021-05-17
  • 2022-12-23
  • 2021-05-26
  • 2021-12-05
相关资源
相似解决方案