[Linux] sort uniq로 중복 라인 제거하기

 

Sample 파일

[root@linux-1 test]# cat list.txt 
555
444
888
888
777
777
777
000
222
aaa
ddd
ggg
ggg
ggg
aaa
ccc
zzz

 

 

# cat list.txt | sort    중복행을 제거하기 전에 sort로 파일을 정렬합니다.
[root@linux-1 test]# cat list.txt | sort
000
222
444
555
777
777
777
888
888
aaa
aaa
ccc
ddd
ggg
ggg
ggg
zzz

 

 

# cat list.txt | sort | uniq uniq 명령어로 중복라인을 제거합니다. (중복 라인중에 하나의 라인만 출력)
[root@linux-1 test]# cat list.txt | sort | uniq 
000
222
444
555
777
888
aaa
ccc
ddd
ggg
zzz

 

 

 

# cat list.txt | sort | uniq -u -u 옵션으로 중복이 없는 라인만 출력합니다.
[root@linux-1 test]# cat list.txt | sort | uniq -u 
000
222
444
555
ccc
ddd
zzz

 

 

# cat list.txt | sort | uniq -c -c 옵션으로 같은 라인이 몇번 나오는지 표시합니다.
[root@linux-1 test]# cat list.txt | sort | uniq -c
      1 000
      1 222
      1 444
      1 555
      3 777
      2 888
      2 aaa
      1 ccc
      1 ddd
      3 ggg
      1 zzz

 

 

# cat list.txt | sort | uniq -d -d 옵션으로 중복 라인중 하나만 출력합니다. 
[root@linux-1 test]# cat list.txt | sort | uniq -d
777
888
aaa
ggg

 

 

# cat list.txt | sort | uniq -D -D 옵션으로 중복 라인 전체를 출력합니다.
[root@linux-1 test]# cat list.txt | sort | uniq -D
777
777
777
888
888
aaa
aaa
ggg
ggg
ggg

'IT' 카테고리의 다른 글

[OS] Process State(프로세스 상태 종류)  (0) 2020.07.12
[Linux] 패스워드 없이 ssh 접속하기  (0) 2020.07.08
[Linux] dig 예제 정리  (0) 2020.07.06
[Linux] 리눅스 CD 명령어 예제  (0) 2020.07.05
[Linux] hpssacli 명령어 정리  (0) 2020.07.03

댓글

Designed by JB FACTORY

loading