bash - Get first N occurances of uniq lines, not only one -
i have file rows 2 fields separated whitespace:
fielda fieldx fieldb fieldx fieldc fieldx fieldd fieldx fielde fieldx fielda fieldy fieldb fieldy fieldc fieldy
i need first n rows of type in second column. sort -k2 | uniq -f1 --all-repeated=prepend | grep "^$" -a3
should work uniq -f1
gives me different uniq -f1 --all-repeated=prepend
. understand correctly prepend should add emtpy line before unique chunk?
or there better approach?
thanks
here's 1 idea using awk
:
awk -v maxlines=<n> ' ++count[$2] <= maxlines { print } '
that not require sorting file (but still sort first if there other reasons want to...).
Comments
Post a Comment