Reputation: 11298
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
Reputation: 7616
Use this:
(\-\- 1\.3\.6\.1\.4\.1\.16213\b[^\r\n]*[\r\n]+[^\r\n]*OBJECT-TYPE[^\r\n]*)([\r\n]+ [^\r\n]*)*[\r\n]*
$1\n
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
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