Curly braces in regular expressions, sed

Johnny Rosenberg gurus.knugum at gmail.com
Tue Jan 6 19:49:38 UTC 2015


Seems like there is something that I misunderstood badly here. Here's an
example that I don't understand:

I created a text file to use for this example. Its name is ”x” and it looks
like this:
x|2:31,93|x
x|2:04,59|x
x|10:03,93|x
x|2:12,75|x
x|2:33,29|x
x|2:25,70|x

The numbers are times in minutes and seconds and 1/100-seconds. I use a
decimal comma, since we do that in my country.

Now I want to separate the times from the rest with sed. There are many
ways to do this, and awk is probably easier in this example, but this is
only an example. My real files have much longer lines so I made this file
since its lines are very much shorter…

So I use the following command:
sed -r 's/.*([0-9]{1,2}:[0-9]{2},[0-9]{2}).*/\1/' x
So I'm looking for something one or two digits followed by a colon, then
two digits followed by a comma and another two digits.

I expected this output:
2:31,93
2:04,59
10:03,93
2:12,75
2:33,29
2:25,70

However, this is what I got:
2:31,93
2:04,59
0:03,93
2:12,75
2:33,29
2:25,70

Why is one digit missing in the third line?


Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20150106/e15990ef/attachment.html>


More information about the ubuntu-users mailing list