I want to do non-greedy pattern (regular expression) matching in awk
.
Here is an example:
echo "@article{gjn, Author = {Grzegorz J. Nalepa}, " | awk '{ sub(/@.*,/,""); print }'
Is it possible to write a regular expression that selects the shorter string?
@article{gjn,
instead of this long string?:
@article{gjn, Author = {Grzegorz J. Nalepa},
I want to get this result:
Author = {Grzegorz J. Nalepa},
I have another example:
echo ",article{gjn, Author = {Grzegorz J. Nalepa}, " | awk '{ sub(/,[^,]*,/,""); print }' ↑ ↑^^^^^
Note that I changed the @
characters to comma (,
) characters
in the first position of both the input string and the regular expression
(and also changed .*
to [^,]*
).
Is it possible to write a regular expression that selects the shorter string?
, Author = {Grzegorz J. Nalepa},
instead of the longer string?:
,article{gjn, Author = {Grzegorz J. Nalepa},
I want to get this result:
,article{gjn
Author
following a comma and whitespace, followed by whitespace followed by=
followed by whitespace followed by{
followed by any non-}
followed by}
, although this requires (among other things) that you can't nest{}
inside the= { ... }
part. – jw013 Oct 1 '12 at 17:02