vels4j
vels4j

Reputation: 11298

Notepad++ RegEx: Search two words in subsequent lines

Consider the following text

-- 1.3.6.1.4.1.16213.2.3.1.2
    xfsCDMStatusTable OBJECT-TYPE
        SYNTAX SEQUENCE OF XfsCDMStatusEntry
        MAX-ACCESS not-accessible
        STATUS current
        DESCRIPTION
            "Define the set of MIB Variables for the CDM status table."
        ::= { xfsCDMV1 2 }


    -- 1.3.6.1.4.1.16213.2.3.1.2.1
    xfsCDMStatusEntry OBJECT-TYPE
        SYNTAX XfsCDMStatusEntry
        MAX-ACCESS not-accessible
        STATUS current

Need to filter lines which contains "1.3.6.1.4.1.16213" in first line and "OBJECT-TYPE" in next line.

Output like

 -- 1.3.6.1.4.1.16213.2.3.1.2
    xfsCDMStatusTable OBJECT-TYPE
 -- 1.3.6.1.4.1.16213.2.3.1.2.1
    xfsCDMStatusEntry OBJECT-TYPE

Can someone help with Regex pattern.

Upvotes: 4

Views: 283

Answers (2)

Peter Thoeny
Peter Thoeny

Reputation: 7616

Use this:

  • Find what: (\-\- 1\.3\.6\.1\.4\.1\.16213\b[^\r\n]*[\r\n]+[^\r\n]*OBJECT-TYPE[^\r\n]*)([\r\n]+ [^\r\n]*)*[\r\n]*
  • Replace with: $1\n
  • "Regular expression" checked
  • ". matches newline" unchecked

Content example:

-- 1.3.6.1.4.1.16213.2.3.1.2
xfsCDMStatusTable OBJECT-TYPE
    SYNTAX SEQUENCE OF XfsCDMStatusEntry
    MAX-ACCESS not-accessible
    STATUS current
    DESCRIPTION
        "Define the set of MIB Variables for the CDM status table."
    ::= { xfsCDMV1 2 }


-- 1.3.6.1.4.1.16213.2.3.1.2.1
xfsCDMStatusEntry OBJECT-TYPE
    SYNTAX XfsCDMStatusEntry
    MAX-ACCESS not-accessible
    STATUS current


-- 1.3.6.1.4.1.16213.2.3.1.2
xfsCDMStatusTable OBJECT-TYPE
    SYNTAX SEQUENCE OF XfsCDMStatusEntry
    MAX-ACCESS not-accessible
    STATUS current
    DESCRIPTION
        "Define the set of MIB Variables for the CDM status table."
    ::= { xfsCDMV1 2 }


-- 1.3.6.1.4.1.xxxxx.2.3.1.2
xfsCDMStatusTable OBJECT-TYPE
    SYNTAX SEQUENCE OF XfsCDMStatusEntry
    MAX-ACCESS not-accessible
    STATUS current
    DESCRIPTION
        "Define the set of MIB Variables for the CDM status table."
    ::= { xfsCDMV1 2 }

After [Replace All]:

-- 1.3.6.1.4.1.16213.2.3.1.2
xfsCDMStatusTable OBJECT-TYPE
-- 1.3.6.1.4.1.16213.2.3.1.2.1
xfsCDMStatusEntry OBJECT-TYPE
-- 1.3.6.1.4.1.16213.2.3.1.2
xfsCDMStatusTable OBJECT-TYPE
-- 1.3.6.1.4.1.xxxxx.2.3.1.2
xfsCDMStatusTable OBJECT-TYPE
    SYNTAX SEQUENCE OF XfsCDMStatusEntry
    MAX-ACCESS not-accessible
    STATUS current
    DESCRIPTION
        "Define the set of MIB Variables for the CDM status table."
    ::= { xfsCDMV1 2 }

Upvotes: 0

JonM
JonM

Reputation: 1374

Try this expression:

(?-s)^(?:(?:(?!.*?\R+.*?\bOBJECT-TYPE\b).*?$(?:\R+|$))|(^.*?\R+.*?\bOBJECT-TYPE\b.*?$))

Replace with $1

It will take an input like this:

-- 1.3.6.1.4.1.16213.2.3.1.2
xfsCDMStatusTable OBJECT-TYPE
    SYNTAX SEQUENCE OF XfsCDMStatusEntry
    MAX-ACCESS not-accessible
    STATUS current
    DESCRIPTION
        "Define the set of MIB Variables for the CDM status table."
    ::= { xfsCDMV1 2 }


-- 1.3.6.1.4.1.16213.2.3.1.2.1
xfsCDMStatusEntry OBJECT-TYPE
    SYNTAX XfsCDMStatusEntry
    MAX-ACCESS not-accessible
    STATUS current


-- 1.3.6.1.4.1.16213.2.3.1.2
xfsCDMStatusTable OBJECT-TYPE
    SYNTAX SEQUENCE OF XfsCDMStatusEntry
    MAX-ACCESS not-accessible
    STATUS current
    DESCRIPTION
        "Define the set of MIB Variables for the CDM status table."
    ::= { xfsCDMV1 2 }

and output the following:

-- 1.3.6.1.4.1.16213.2.3.1.2
xfsCDMStatusTable OBJECT-TYPE
-- 1.3.6.1.4.1.16213.2.3.1.2.1
xfsCDMStatusEntry OBJECT-TYPE
-- 1.3.6.1.4.1.16213.2.3.1.2
xfsCDMStatusTable OBJECT-TYPE

If you'd like to only specify the lines that have the value 1.3.6.1.4.1.16213 then use the following:

(?-s)^(?:(?:(?!.*?1\.3\.6\.1\.4\.1\.16213.*?\R+.*?\bOBJECT-TYPE\b).*?$(?:\R+|$))|(^.*?\R+.*?\bOBJECT-TYPE\b.*?$))

Upvotes: 2

Related Questions