1

I have a file, with header

name, age, id, address 
Smith, 18, 201392, 19 Rand Street, USA
Dan, 19, 029123, 23 Lambert Rd, Australia
Smith, 20, 192837, 61 Apple Rd, UK
Kyle, 25, 245123, 103 Orange Rd, UK

And I'd like to sort out duplicates on names, so the result will be:

Smith, 18, 201392, 19 Rand Street, USA
Dan, 19, 029123, 23 Lambert Rd, Australia
Kyle, 25, 245123, 103 Orange Rd, UK

# prints 3 for 3  unique rows at column name

I've tried sort -u -t, -k1,1 file, awk -F"," '!_[$1]++' file but it doesn't work because I have commas in my address.

oguz ismail
  • 1
  • 16
  • 47
  • 69
quickhelp
  • 99
  • 6

1 Answers1

0

Well, you changed the functionality since the OP, but this should get you unique names in your file (considering it's named data), unsorted:

#!/bin/bash
sed "1 d" data | awk -F"," '!_[$1]++ { print $1 }'

If you need to sort, append | sort to the command line above.

And append | wc -l to the command line to count lines.

Niloct
  • 9,491
  • 3
  • 44
  • 57