Count disctinct values for each columns of a file with awk
✓ Published0🌍 Public
Aant1j
Last edited Jul 9, 2015
Created on Jul 9, 2015
This example uses an awk script to count distinct values in every column of a CSV file, writing each column’s unique entries and their occurrence counts to a separate output CSV named after the original file and column header. The script first extracts the header row to create per-column output files, then iterates over all subsequent rows, tallying values in a two-dimensional associative array keyed by field name and value. In the END block, it splits those keys to write the final counts. The awk code relies on built-in features like the `FS` field separator, the `split` function, and the `SUBSEP` separator for array keys.
AI-generated description