·터미널 명령어

join

텍스트 처리

쓰는 꼴

join -1 1 -2 1 [file1] [file2]

두 파일을 공통 칸으로 이어 붙입니다. 데이터베이스의 join과 같지만, 두 파일이 그 칸으로 미리 정렬돼 있지 않으면 줄이 조용히 빠집니다.

자주 쓰는 옵션

옵션
-1Which field to use in the first file
-2Which field to use in the second file
-tThe field separator, as in -t,
-aAlso print unpaired lines from that file, an outer join
-vPrint only the unpaired lines from that file
-eFill missing fields with this string
-oChoose which fields the output holds

예시

join -t, -1 1 -2 1 a.csv b.csv

Inner join on the first column.

join -a1 left.txt right.txt

Keeps the unmatched lines from the left file.

파이프로 이어 쓰는 것이 본래 용도입니다. 한 명령이 다 하는 것보다 셋을 잇는 편이 짧습니다.

읽는 방법

  • 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
  • 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
  • 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.

자주 묻는 것

Q. join은 무엇을 하나요?

두 파일을 공통 칸으로 이어 붙입니다. 데이터베이스의 join과 같지만, 두 파일이 그 칸으로 미리 정렬돼 있지 않으면 줄이 조용히 빠집니다.

Q. 어떻게 치나요?

join -1 1 -2 1 [file1] [file2] — 대괄호는 생략할 수 있는 자리입니다.

Q. 옵션은 몇 개나 자주 쓰나요?

여기 정리한 것은 7개입니다. 전체 목록은 man join에 있습니다. 이 명령은 텍스트 처리 갈래입니다.

같이 보는 명령

man 페이지: man join