Angelo
Angelo

Reputation: 5059

Shell Scripting: get unique items in a file

The question is based on the function uniq unless you have some other suggestion.

I have a file which has only one column with n number of rows, and contains redundant names of items randomly.

I have tried command uniq filename>filename2 to get the unique items in filename2... but it doesn't work. I still get the same list.

Any suggestions as to how I can tackle this problem?

Thank you in advance.

Upvotes: 1

Views: 856

Answers (2)

wich
wich

Reputation: 17117

Try sort -u. uniq only filters out repeated lines, not duplicate lines spread out over the input.

Upvotes: 3

RemoteSojourner
RemoteSojourner

Reputation: 743

Try sort -u filename > filename2

Upvotes: 2

Related Questions