To get all the columns in a CSV file based on unique values of particular column

cat sample.csv
 
ID,Name,no
1,AAA,1
2,BBB,1
3,AAA,1
4,BBB,1
cut -d',' -f2 sample.csv | sort | uniq

this gives only the 2nd column values

Name
AAA
BBB

How to I get all the columns of CSV along with this?

Hello,

If you will see the entries carefully there is no entry(row) is completly duplicate, so if I can give you a awk solution which is based on to find the duplicate reows will give null result for your requested input.

Here is an example for finding the uniqe values, hope it may help.

Input file is:

ID,Name,no
1,AAA,1
2,BBB,1
1,AAA,1
4,BBB,1
awk '!a[$0]++'  file_name

Output will be as follows.

ID,Name,no
1,AAA,1
2,BBB,1
4,BBB,1

Thanks,
R. Singh