Curly braces in regular expressions, sed
Nathan Dorfman
na at rtfm.net
Tue Jan 6 20:25:47 UTC 2015
On Tue, Jan 6, 2015 at 2:49 PM, Johnny Rosenberg <gurus.knugum at gmail.com> wrote:
> So I use the following command:
> sed -r 's/.*([0-9]{1,2}:[0-9]{2},[0-9]{2}).*/\1/' x
> [...]
> Why is one digit missing in the third line?
Simple: because the '*' operator that comes right before it is
"greedy," meaning it will match as much as possible, including the
first digit if it exists.
If you include the first | character in your pattern, it should work
for the example you posted. Like this: sed -r
's/.*\|([0-9]{1,2}:[0-9]{2},[0-9]{2}).*/\1/' x
-nd.
More information about the ubuntu-users
mailing list