I have a text file, fred.txt:
% cat -e fred.txt
00:$
00:04:$
01:00:23:34$
01:$
01:40:$
01:40:32:$
%
I can grep for a line with 2 digits and a colon:
% pcregrep -e '[\d]{2}:' fred.txt
00:
00:04:
01:00:23:34
01:
01:40:
01:40:32:
%
but when I try to get repeating patterns of that pattern, it doesn't find them:
% pcregrep -e '[[\d]{2}:]{2}' fred.txt
%
I'm looking to get the same output as this:
% pcregrep -e '[\d]{2}:[\d]{2}:' fred.txt
00:04:
01:00:23:34
01:40:
01:40:32:
%
Eventually I'll be looking for more nested repeating patterns in a larger file so I don't want to define each time the pattern repeats. How do I grep for the lines that have that pattern repeating?
[\d]
, that's the same as\d
. The[ ]
are used to define a character class, but\d
is already a character class so you don't need to put it in[ ]
unless you combine it with something else like[\dabc]
. Then, as shown by schrodigerscatcuriosity's answer, you group things with parentheses(foo){2}
and not square brackets[foo]{2}
.