Artificial intelligent assistant

keep only rows in file that occur n times I have a `test.txt` file that contains one string per row as follows: AA BNT AA KIO LO LO POY LO II LO AA AA II AA BNT POY YTR BNT LL BNT How can I use linux to go through the file and return only rows that occur 4 times? Desired output: AA BNT LO Thanks

Using AWK:


awk '{ seen[$0]++ } seen[$0] == 4' test.txt


This counts the number of times each line has been seen, and outputs a line when the count is exactly four (so lines seen four or more times are output once).

If you only want to see lines which appear exactly four times, use this instead:


awk '{ seen[$0]++ } END { for (line in seen) if (seen[line] == 4) print line }' test.txt

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy d08be248beb70ed4c276dd7c0721117c