我们编辑模式匹配

Vi editor pattern matching

假设日志文件中的数据格式如下。

    *******************************************
      Refreshing token for  app foo1
    *******************************************
      Refreshing token for  app foo2
    *******************************************
      Refreshing token for  app foo3
      Update application with name: foo3
      Done
      Waiting 1 second
    *******************************************

此数据表明 foo1 和 foo2 的刷新令牌不完整,而 foo3 的刷新令牌令牌已完成。

我需要分离未完成刷新令牌的应用程序。

如何使用 vi 匹配 foo1 和 foo2 editor.Any 感谢帮助。

如果您正在使用 vim,打开文件:

<Esc>       To go to command mode
:1 <Enter>  to go to line 1
/           Start a search
\d          a digit
\n          followed by a newline
\*          followed by an escaped splat
<Enter>     You will be positioned at the first match
n           go to the next match

左下角看起来像这样:

/\d\n\*

当然,该数字与您的测试数据匹配,但您必须对其进行调整以匹配您的真实数据。

这也有效

 :set hlsearch
    /\*\{30,}\n\s\+Refreshing\stoken\sapp\s\a\a\a\d\n\*\{30,}
  • :set hlsearch 高亮搜索结果
  • *{30,} 匹配包含特殊字符 * 出现超过 30 次的行
  • \n 匹配新行
  • \s\+ 多次匹配白色 space
  • \a 匹配一个字符
  • \d 匹配一个数字