Reputation: 428
I'd like to grep
unique line. This is the file content:
this is line 1
this is line 1
this is line 2
this is line 1
this is line 1
I just want to output this is line 2
to my shell.
How can I do that?
Upvotes: 2
Views: 20419
Reputation: 41460
Here is an awk
solution:
awk '{a[$0]++} END {for (i in a) if (a[i]==1) print i}' file
this is line 2
Upvotes: 4
Reputation:
Check out man uniq
:
-u Only output lines that are not repeated in the input.
With that in mind, sort does a pairwise comparison to see if it's neighbor matches, meaning that you need to sort your output before feeding it to uniq
:
$ sort my_list.txt | uniq -u
Upvotes: 5
Reputation: 9075
sort x.txt |uniq -u
assuming your file is in x.txt which gives
this is line 2
Upvotes: 11