Example input CSV file. The file is named transaction.csv

invoice_number,item_id,qty
#001,1,2
#001,2,2
#002,2,2
#003,1,2
#003,5,3
#004,2,2
#003,5,3
#005,2,2

The goal is to get the list of unique invoice_number

#001
#002
#003
#004
#005

Step

  1. Run awk command split by comma (-F), then print the first column. awk -F ',' '{print $1}' transaction.csv
  2. Add sorting with unique params sort -u. Use -r to get reverse order
  3. Final command is awk -F ',' '{print $1}' transaction.csv | sort -u

Reference