'man uniq' documents the -f=N and -s=N options which make uniq skip the first N fields/characters respectively when comparing lines, but how would you force uniq to skip the last N fields/characters?
If you want the functionality of sorting first and then keeping only one line for each unique combination of the fields you are sorting on, you can make do with the unix utility sort alone.
As an example, consider the following file, named some_data
a;c;4
a;b;9
a;b;6
We want to sort by the first and second field, and leave the third field alone, so we do a stable sort, like this:
$ sort -k1,1 -k2,2 -t';' --stable some_data
which gives
a;b;9
a;b;6
a;c;4
Now say we'd like to keep only unique combinations of the first and second column. Then we'd do this:
$ sort -k1,1 -k2,2 -t';' --stable --unique some_data
which gives
a;b;9
a;c;4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With