Reputation: 1210
I have two examples:
1.
$ echo "Lorem ipsum dolor sit amet" | awk '{gsub(/L[^r]r/,""); print}'
em ipsum dolor sit amet
2.
$ echo "Loorem ipsum dolor sit amet" | awk '{gsub(/L[^r]r/,""); print}'
Loorem ipsum dolor sit amet
Why the second example does not work the same as the first?
In the first example, the record of [^r]
is treated as a single character? Is it because one "o"
is deleted?
Upvotes: 2
Views: 589
Reputation: 85765
L[^r]r
matches L
followed by any single character that isn't r
followed by r
like Lor
. To match Loor
you would want L[^r]+r
. The +
quantifier means one or more characters that are not r
.
$ echo "Loorem ipsum dolor sit amet" | awk '{gsub(/L[^r]+r/,""); print}'
em ipsum dolor sit amet
Upvotes: 5