user3116123
user3116123

Reputation: 129

Extract line that don't repeat

I have a file with duplicate lines and I need to extract only the non repeating lines.

For example, I have

12
13
14
12
13
15

and the desired output is:

14
15

Upvotes: 1

Views: 2377

Answers (1)

Chris Seymour
Chris Seymour

Reputation: 85785

To find the unique lines in a file you can use uniq -u (required sorted file):

$ sort file | uniq -u    
14
15

An alternative method using awk:

$ awk '{a[$0]++}END{for(k in a)if(a[k]==1)print k}' file
14
15

Upvotes: 2

Related Questions