Tuesday, September 6, 2022

[SOLVED] using "grep" to print the lines where the same sequence of 4 or more consecutive characters comes in at least 3 times

Issue

I'm trying to find the lines where the same sequence of 4 or more consecutive characters comes in at least 3 times, using the grep command

 grep '^.*\(....\)*\1*\1*' file.name

for ex

  ADShDS DFDFG HGFDFDFD DFDFD
  ASFG VVFGTTTE DSrFD GFFDSD C
  KKKYX KKKYXFF KaKFVBB KKKYXY

expected output

  ADShDS DFDFG HGFDFDFD DFDFD
  KKKYX KKKYXFF KaKFVBB KKKYXY

but there is something wrong !?


Solution

I suggest:

grep '\(....\).*\1.*\1' file

or

grep -E '(....).*\1.*\1' file

See: The Stack Overflow Regular Expressions FAQ



Answered By - Cyrus
Answer Checked By - Terry (WPSolving Volunteer)