I have a large data file of comma separated variables. I need to remove all lines where the first entry (a number up to four digits) is non-unique. A typical example of what I am working with is below
1062,"Mark","Michaelson","1"
1062,"Mark","Michaelson","2"
1062,"Mark","Michaelson","4120"
1075,"Dan","Danson",15"
1075,"Dan","Danson",185"
so in the brief example above, I wish to retain the first and forth lines and discard the rest.
I have been trying to use Vim Regex to achieve this
:0/^\w*/+,$g//d
but of course that deletes all lines apart from the first
sort
like this:sort -u -t, -k1,1 myfile
I know it is not in vim but it is a pretty straighforward way to do that. See man sort-u
is uniq result,-t,
sets,
as the delimitor and-k1,1
gives the fields to use for the sort.Missing argument in parameter list
. I will figure it out, I'm sure