I have a large dataframe, in which one of the fields("ID") correspond to a unique identifier. However, there are multiple instances of that value, depending on the binary combination of additional measurements("strucureA" and "structureB"). I want to devise a way to filter the rows using awk to shows measurements associated with an ID that only has 4 instances in the initial dataframe.
I can envision doing this in two parts, first counting the number of instances using uniq -c or a awk array and saving to a file, and then using that new file to filter the initial dataframe with awk arrays and FNR==NR. But I was hoping that there may be a way for awk to tally the count and then print a group of rows that meet a criteria (e.g. an entry appearing X number of times ).
> Initial table
ID structureA structureB
sample_1 1 1
sample_2 1 1
sample_2 2 1
sample_2 1 2
sample_2 2 2
sample_3 1 1
sample_3 2 1
sample_3 3 1
sample_4 1 1
sample_4 2 1
sample_4 3 1
sample_4 4 1
> Desired table
ID structureA structureB
sample_2 1 1
sample_2 2 1
sample_2 1 2
sample_2 2 2
sample_4 1 1
sample_4 2 1
sample_4 3 1
sample_4 4 1
$1
is exactly 4, you want to print those 4 lines? Is that all?