46

Text file:

1 1
2 2
3 3
1 1

I want to catch 1 1 as duplicated

0

3 Answers 3

121

Your question is not quite clear, but you can filter out duplicate lines with uniq:

sort file.txt | uniq

or simply

sort -u file.txt

(thanks RobEarl)

You can also print only repeating lines with

sort file.txt | uniq -d
Sign up to request clarification or add additional context in comments.

3 Comments

sort -u file.txt would also filter out duplicates
actually that works for me sort file.txt | uniq -d Thank, Lev
I will keep in mind thank you, Lev.
5

One way using GNU awk:

awk 'array[$0]++' file.txt 

Results:

1 1

Comments

1

You can use it easily:

sort -u file.txt

OR

awk '!x[$0]++' file.txt

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.