Your PCRE pattern (that only matches 52 occurrences of any 0+ chars, as few as possible, up to and including |
char, and does not check any text beyond that) contains a repeated capturing group, when the engine matches, it also places each 0+ chars before each |
and the |
char into a group, and then re-writes the value upon each iteration. In some implementations, it causes the error you provided.
Note you do not need a PCRE regex for the task since to match any char but |
you may use [^|]
and then use a mere POSIX ERE pattern (enabled with -E
option) with grep
:
grep -En "^([^|]*\|){52}[^|]*$"
Note the [^|]*$
added at the end. It matches any 0+ chars other than |
and then assert the end of line position. So, only lines containing 53 |
-separated fields are matched.
Else, you might consider an awk solution (as PS suggests):
awk -F'|' '{if (NF==53) {print NR ":" $0;}}'
where we check for 53 |
-separated fields and print the line number, :
and the line itself.