3

I have a sorted words list, line by line file like so:

apple
apple
grapes
lime
orange
orange
pear
pear
peach
strawberry
strawberry

I only want to print out unique lines and drop duplicates:

grapes
peach
lime

How can I do this with sed, awk or perl?

cuonglm
  • 153,898

3 Answers3

10

That's the job for uniq:

$ LC_ALL=C uniq -u file
grapes
lime
peach

If you want other tools, like perl:

perl -nle '$h{$_}++; END {print for grep { $h{$_} == 1 } %h}' <file
cuonglm
  • 153,898
1

Try this AWK!

awk '{a[$0]++} END {for (x in a) if (a[x] == 1) print x}'
Firefly
  • 286
1
awk '{arr[$1]++} END {for (i in arr) {if (arr[i]==1) {print i} }}' 1
grapes
lime
peach
jai_s
  • 1,500