Search code examples
bashshellawktcsh

Unique entry set in the first column of all csv files under directory


I have a list of comma separated files under the directory. There are no headers, and unfortunately they are not even the same length for each row.

I want to find the unique entry in the first column across all files.

What's the quickest way of doing it in shell programming?

awk -F "," '{print $1}' *.txt | uniq

seems to only get uniq entries of each files. I want all files.


Solution

  • Shortest is still using awk (this will print the row)

    awk -F, '!a[$1]++' *.txt
    

    to get just the first field

    awk -F, '!a[$1]++ {print $1}' *.txt