
다음과 같은 줄이 포함된 텍스트 파일이 있습니다.
This is a thread 139737522087680
This is a thread 139737513694976
This is a thread 139737505302272
This is a thread 139737312270080
.
.
.
This is a thread 139737203164928
This is a thread 139737194772224
This is a thread 139737186379520
각 줄의 고유성을 어떻게 확인할 수 있나요?
노트:목표는 파일을 테스트하는 것이며 중복된 줄이 있는 경우 파일을 수정하는 것이 아닙니다.
답변1
이상한 해결책 :
awk 'a[$0]++{print "dupes"; exit(1)}' file && echo "no dupes"
답변2
[ "$(wc -l < input)" -eq "$(sort -u input | wc -l)" ] && echo all unique
답변3
사용 sort
/ uniq
:
sort input.txt | uniq
중복된 행만 확인하려면 -d
uniq 옵션을 사용하십시오. 중복된 행만 표시되며, 그렇지 않은 경우 아무것도 표시되지 않습니다.
sort input.txt | uniq -d
답변4
나는 보통 sort
파일을 제출한 다음 uniq
중복 항목 수를 세는 데 사용하고 sort
다시 목록 하단에 중복 항목이 표시됩니다.
귀하가 제공한 예제의 복사본을 추가했습니다.
$ sort thread.file | uniq -c | sort
1 This is a thread 139737186379520
1 This is a thread 139737194772224
1 This is a thread 139737203164928
1 This is a thread 139737312270080
1 This is a thread 139737513694976
1 This is a thread 139737522087680
2 This is a thread 139737505302272
한동안 매뉴얼 페이지를 읽지 않았기 때문에 uniq
신속하게 대안을 찾았습니다. 중복 항목만 보려면 다음과 같이 두 번째 정렬이 필요하지 않습니다.
$ sort thread.file | uniq -d
This is a thread 139737505302272