0

我在 Windows 7 上使用 gVim 7.4.68。我有一个文本文件,其内容如下所示。下面给出的两个条目仅作为示例。文本文件有 100 个这样的字段,其中包含 Pseudo Name、Symmetrix ID、Logical Device、State/policy 和路径相关信息。

Pseudo name=emcpowermg
Symmetrix ID=000123456781234
Logical device ID=01D3
state=alive; policy=SymmOpt; priority=0; queued-IOs=0
==============================================================================
---------------- Host ---------------   - Stor -   -- I/O Path -  -- Stats ---
###  HW Path                I/O Paths    Interf.   Mode    State  Q-IOs Errors
==============================================================================
   1 qla2xxx                   sdga      FA 10bA   active  alive      0      1
   0 qla2xxx                   sdgb      FA  7bA   active  alive      0      0

Pseudo name=emcpowerdl
Symmetrix ID=000123456780000
Logical device ID=0427
state=alive; policy=SymmOpt; priority=0; queued-IOs=0
==============================================================================
---------------- Host ---------------   - Stor -   -- I/O Path -  -- Stats ---
###  HW Path                I/O Paths    Interf.   Mode    State  Q-IOs Errors
==============================================================================
   1 qla2xxx                   sdaca     FA  9bA   active  alive      0      0
   0 qla2xxx                   sdaci     FA  8bA   active  alive      0      0

我只想过滤除 Symmetrix ID 和逻辑设备之外的所有其他内容,以便整个文件充满以下条目:

Symmetrix ID=000123456781234
Logical device ID=01D3
Symmetrix ID=000123456780000
Logical device ID=042

试过:

%v/^Symmetrix.*\nLogical/d

%v/^Symmetrix.*\rLogical/d

然后尝试复制粘贴这些内容,以便 ^M 正确显示:

%v/^Symmetrix.*^M^Logical/d

但这些都不起作用。它不过滤任何东西,我得到一个空白屏幕。请让我知道我哪里出错了。

我最近开始使用 gVim 并且仍然掌握它。

问候, pmu

4

1 回答 1

4

This command works with the given sample:

:v/^\(Symmetrix\|Logical\)/d

We look for lines that don't start with either Symmetrix or Logical and we delete them.

The same command with less backslashes thanks to \verymagic:

:v/^\v(Symmetrix|Logical)/d

(edit) The main reason behind the failing of your attempts is that you actually match the Symmetrix line but not the Logical line, even if you introduced a \nLogical in your pattern: when the pattern spans multiple lines, the actual matched line is the first line, not the two lines you targeted in your pattern.

于 2013-11-10T18:52:12.827 回答