Hi,
I am looking for a solution to grep for minimum 5 or 6 characters in a file, otherwise ignore.
Example
1121221222
2212121211
1221122122
2121222222
2222112222
1211221121
So it greps 5 X 1 or 6 X 1
2212121211
1211221121
Thanks for you help
rdrtx1
2
try awk:
awk 'gsub(c,c)>=5' c="1" infile
Thanks for the reply.
I think I should have asked different.
I meant minimum 5 or 6 but not more than 6.
awk solution is great
Thanks
---------- Post updated at 12:23 PM ---------- Previous update was at 12:21 PM ----------
Thank,
Figured it out myself
awk 'gsub(c,c)==5' c="1"
awk 'gsub(c,c)==6' c="1"
Thanks this forum is awesome
rdrtx1
4
in one pass:
awk 'gsub(c,c)==5 || gsub(c,c)==6' c="1" infile
And, slightly faster:
awk '(n=gsub(c,c))==5 || n==6' c="1" infile
And, if someone wants to try any of these awk
suggestions on a Solaris/SunOS system, change awk
to /usr/xpg4/bin/awk
or nawk
.
RudiC
6
How about
awk -F1 'NF==6;NF==7' file
2212121211
1211221121
1 Like
Not necessarily clearer but this should work too:
awk 'gsub(c,c)~/^[56]$/' c=1 file
or
awk -F1 'NF~/^[67]$/' file