Extract line that don't repeat

2.2k views Asked by At

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
1

There are 1 answers

0
Chris Seymour On

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