comm
텍스트 처리
쓰는 꼴
comm -12 [file1] [file2]정렬된 두 파일을 견주어 왼쪽만, 오른쪽만, 둘 다를 세 칸으로 보여 줍니다. 정렬이 안 돼 있으면 결과가 엉뚱하고, 옵션은 칸을 고르는 것이 아니라 숨기는 것입니다.
자주 쓰는 옵션
| 옵션 | 뜻 |
|---|---|
| -1 | Hide column 1, the lines only in the first file |
| -2 | Hide column 2, the lines only in the second file |
| -3 | Hide column 3, the lines in both |
| -i | Compare without regard to case |
| --check-order | GNU: stop when the input is not sorted |
예시
comm -12 a.txt b.txtOnly the lines both files share.
comm -23 a.txt b.txtOnly the lines the first file has.
comm -13 <(sort a.txt) <(sort b.txt)Only the lines the second file added (bash).
파이프로 이어 쓰는 것이 본래 용도입니다. 한 명령이 다 하는 것보다 셋을 잇는 편이 짧습니다.
읽는 방법
- 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
- 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
- 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.
자주 묻는 것
Q. comm은 무엇을 하나요?
정렬된 두 파일을 견주어 왼쪽만, 오른쪽만, 둘 다를 세 칸으로 보여 줍니다. 정렬이 안 돼 있으면 결과가 엉뚱하고, 옵션은 칸을 고르는 것이 아니라 숨기는 것입니다.
Q. 어떻게 치나요?
comm -12 [file1] [file2] — 대괄호는 생략할 수 있는 자리입니다.
Q. 옵션은 몇 개나 자주 쓰나요?
여기 정리한 것은 5개입니다. 전체 목록은 man comm에 있습니다. 이 명령은 텍스트 처리 갈래입니다.
같이 보는 명령
man 페이지: man comm