【问题标题】:Trying to make a filter with grep试图用 grep 做一个过滤器
【发布时间】:2010-06-25 13:17:29
【问题描述】:

我正在尝试制作一个过滤器来捕获所有.exe 文件行。例如,从此:

[05/Apr/2010:11:00:01 -0300] /~mauro/Lista_conceitos_BD_2004.DOC 200 46080

[05/Apr/2010:11:00:54 -0300] /~lucia/articles/PROPOR96-Rino.pdf 200 153253

[05/Apr/2010:11:01:32 -0300] /~daniel_leite/RenomearTudo/setup.exe 200 1692017

[05/Apr/2010:11:02:12 -0300] /~grv/tutrv/fig23.jpg 200 22821

[05/Apr/2010:11:04:11 -0300] /~lucia/TechRep/NILCTR981-RMartinse

我想得到这个:

[05/Apr/2010:11:01:32 -0300] /~daniel_leite/RenomearTudo/setup.exe 200 1692017

我正在尝试使用grep -w '*.exe' filteredAccessLog > filteredSuccessIMGAccessLog,但它根本不起作用。如果有人可以提供帮助,我将不胜感激。

【问题讨论】:

    标签: linux bash grep


    【解决方案1】:

    星号表示 *,而 .意思是“任何字符”。试试这个:

    grep "\.exe"filteredAccessLog > filteredSuccessIMGAccessLog

    【讨论】:

      【解决方案2】:

      grep -F .exe filteredAccessLog > filteredSuccessIMGAccessLog

      【讨论】:

      • 我会使用 -F (固定字符串),否则。匹配任何字符。
      【解决方案3】:

      那个星号可能并不像您认为的那样。在正则表达式中,星号表示前一个字符或组的 0 次或多次重复。

      【讨论】:

        【解决方案4】:

        省略星号:

        grep -w '.exe' filteredAccessLog > filteredSuccessIMGAccessLog
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-09-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多