egrep没有得到结果

时间:2017-06-16 07:04:11

标签: linux bash shell grep

我写了一个小脚本,它将egrep来自服务器日志的两个模式

pattern - 'Unable to resolve location classpath:db/migration|Processing PersistenceUnitInfo'

代码段

#/bin/sh
ssh  tomcat@x.x.x.x egrep -e 'Unable to resolve location classpath:db/migration|Processing PersistenceUnitInfo' /usr/local/dd/logs/ddservice.log

执行结果

bash: Processing: command not found
grep: to: No such file or directory
grep: resolve: No such file or directory
grep: location: No such file or directory
grep: classpath:db/migration: No such file or directory

事实上,属于上述模式的关键字很少。如何修改脚本以获取模式。

2 个答案:

答案 0 :(得分:1)

您必须使用搜索字符串中的\来转义空格。

尝试

ssh tomcat@x.x.x.x egrep -e 'Unable\ to\ resolve\ location\classpath\:db/migration|Processing\ PersistenceUnitInfo' /usr/local/dd/logs/ddservice.log

答案 1 :(得分:0)

我在这里有几个假设:

  1. 我没有在egrep和
  2. 之前看到管道
  3. 可能" /"符号应该被转义。这只是第一眼看到我手上没有笔记本电脑。
  4. 这是可行的代码:

    $ ssh username@somehost "egrep -e \"Unable to resolve location classpath:db/migration|Processing PersistenceUnitInfo\" /somepath/test.log"
    Unable to resolve location classpath:db/migration
    Processing PersistenceUnitInfo
    

    然后:

    $ cat 1.log 
    Unable to resolve location classpath:db/migration
    Processing PersistenceUnitInfo