【问题标题】:grep path as a pattern in afilegrep 路径作为文件中的模式
【发布时间】:2018-03-08 04:54:34
【问题描述】:

我有一个下面的文件

cat test.txt 

/mount/u001/oracle/product/12.1.0.2    41004360                                        

/mount/u001/oracle                     7186360 

我只想准确地grep“/mount/u001/oracle”

grep -w "/mount/u001/oracle" test.txt 给出

/mount/u001/oracle/product/12.1.0.2    41004360                                                                        

/mount/u001/oracle                     7186360 


grep "\b/mount/u001/oracle\b" test.txt -- no result                          

grep "^\/mount/u001/oracle\$" test.txt -- no result 

【问题讨论】:

标签: shell grep


【解决方案1】:

哇..这对我有用

  grep "^\/mount/u001/oracle$" test.txt

【讨论】:

  • 感谢本杰明,Sundeep 的帮助 :-)
  • 在这种情况下,您的示例应该单独包含/mount/u001/oracle 行。这个可以重写为grep -Fx '/mount/u001/oracle'
  • @Sandeep 它不工作!我的也很早就工作了,现在没有给出预期的结果:-(我想知道下面没有任何建议!!! grep "^\/mount/u001/oracle$" test.txt
猜你喜欢
  • 2017-09-25
  • 1970-01-01
  • 2021-12-22
  • 1970-01-01
  • 2013-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多