한 파일의 열에서 다른 파일의 단어를 검색하고 일치하는 줄을 인쇄하는 방법은 무엇입니까?

한 파일의 열에서 다른 파일의 단어를 검색하고 일치하는 줄을 인쇄하는 방법은 무엇입니까?

두 개의 파일이 있습니다. 예를 들어 다음 예는 다음과 같습니다.

파일 1:

Polaromonas naphthalenivorans
uncultured bacterium
Leptothrix cholodnii
Clostridium clariflavum
Methylocystis parvus
Calditerrivibrio nitroreducens

파일 2:

Polaromonas naphthalenivorans   143990  0   6   4   0   0
uncultured bacterium    43393   0   11174   285 0   0
Leptothrix cholodnii    26955   0   0   0   0   0
Clostridium clariflavum 2544    0   3   0   0   2
Met parvus  1603    131 0   0   0   197
Caldi nit   998 831 11  70  7   117

원하는 출력:

Polaromonas naphthalenivorans   143990  0   6   4   0   0
uncultured bacterium    43393   0   11174   285 0   0
Leptothrix cholodnii    26955   0   0   0   0   0
Clostridium clariflavum 2544    0   3   0   0   2

답변1

grep이 기능은 다음과 같이 내장되어 있습니다.

grep -Ff file1 file2

의미: file2의 ile1 F에서 고정 문자열을 찾고 ffile2에서 일치하는 행을 보고합니다.

관련 정보