unique 명령어: 중복 제거하기

- 연속된 중복 데이터를 하나만 출력하는 명령어

- 같은 내용이 연속되어 있는 경우에만 중복을 없애는 명령어

 

예시: file1.txt :: 

Seoul Seoul
Seoul
Busan
Busan
busan
1
1
Seoul

 

$ uniqu file1.txt
Seoul Seoul
Seoul
Busan
busan
1
Seoul

 

sort 를 이용하여 중복을 제거하는 방법

$ sort file1.txt | uniq
1
Busan
Seoul
Seoul Seoul
busan

$ sort -u file.txt
1
Busan
Seoul
Seoul Seoul
busan

 

중복 데이터의 개수 세기

$ sort file1.txt | uniq -c
      2 1
      2 Busan
      2 Seoul
      1 Seoul Seoul
      1 busan
      
# uniq -c 결과를 정렬하여 중복이 많은 순으로 출력
$ sort file1.txt | uniq -c | sort -rn
      2 Seoul
      2 Busan
      2 1
      1 busan
      1 Seoul Seoul

# uniq -c 결과를 역 순으로 출력
$ sort file1.txt | uniq -c | sort -n
      1 Seoul Seoul
      1 busan
      2 1
      2 Busan
      2 Seoul

+ Recent posts