How to grep for repeated patterns of repeated patterns?
6
votes
3
answers
7401
views
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?
Asked by Johnny Rollerfeet
(155 rep)
Feb 2, 2022, 06:26 PM
Last activity: Feb 2, 2022, 09:07 PM
Last activity: Feb 2, 2022, 09:07 PM