Reputation: 877
I got some help before here to construct a regexp that would match any lines that started with ":" then anything, then a "(" and after that anything, but it could not end with a ")"
The regexp I used was this:
/:.+ \(.[^)]*$/
It seemes to work reasonably well. I had this input lines:
:web_application_settings (
:isakmp.phase1_DH_groups (
:ike_p1 (
:ike_p1_dh_grp (ReferenceObject
:isakmpkeymanager (lalalal)
And the output was only: :ike_p1_dh_grp (ReferenceObject
But then I happened to add the line:
:isakmpkeymanager ()
This shouldnt match, but it does, which I think is strange. What did I miss in the regexp that allowed this line that ends with a ")" to still match, when I use Do not match: [^)] followed by start to allow it to not match and then end of line.
Upvotes: 1
Views: 272
Reputation: 189648
The .
after the \(
allows any single arbitrary character - including )
- immediately after the opening parenthesis. If that's not what you want to say, take it out.
Upvotes: 1
Reputation: 113924
Try:
awk '/:.+ \([^)]+$/' File
Let's look at the original regex, /:.+ \(.[^)]*$/
, one step at a time:
:
meaning a single colon
.+
meaning one or more of any character. (+
means one or more.)
meaning one blank
\(
meaning one open parens
.
meaning one of any character
[^)]*
meaning zero or more of any character except close parens. (*
means zero or more.)
$
meaning the end of the line.
The problem was step 5 which can match a )
. In the revised regex, this was eliminated and [^)]*
was replaced with [^)]+
.
Upvotes: 2