Sam
Sam

Reputation: 2331

Using something like uniq -f, but instead of ignoring the first n columns, ignore all but the first n columns, without using rev

I can't just use rev because each row may have 2 to 8 columns but basically I just want to use uniq but only based on the first column and not every column after.

Upvotes: 0

Views: 308

Answers (1)

J. Chomel
J. Chomel

Reputation: 8395

From man uniq and other onlie sources (e.g. that one: http://www.folkstalk.com/2012/10/uniq-command-examples-in-unix-and-linux.html),

The -f option is used to skip the first N columns in comparison.

So you'd rather use sort like below, to keep lines in a.txt that are unique regarding the first column:

 sort -k 1,1 -u a.txt

hope this will help.

Upvotes: 1

Related Questions