2013-03-20 5 views
9

현재 단어에서 특정 단어 BML.I을 검색하려고했습니다.문자열에 점이있는 경우 정확한 단어를 grep하는 방법

나는 아래의 명령을 시도 : 그것은 BML

그것이 가능한 정확히 일치하는 grep으로하는 것입니다 단어가 포함되어있는 경우는 모든 결과를 표시

grep -l "BML.I" * 

BML.I

+0

파일 이름이나 파일 내용을 찾으십니까? – Alepac

+0

@Alepac 분명히 그는 콘텐츠를 찾고 있습니다. – Kent

+0

'man grep'을 읽으십시오. –

답변

15

당신 그 (것)들을 도주 할 필요가있다. (마침표)는 기본적으로 모든 문자와 일치하므로 -w를 지정하여 특정 단어와 일치시킵니다.

grep -w -l "BML\.I" * 

위의 두 가지 이스케이프 레벨이 있습니다. 따옴표는 쉘이 BML\.I을 grep에 전달하도록합니다. \grep의 기간을 이스케이프합니다. 당신이 따옴표를 생략 할 경우, 쉘은 기간의 탈출로 \ 해석 (단순히 grep에 이스케이프 기간 전달할 것)

+0

거기에 작은 따옴표가 필요할 수도 있습니다. – filmor

+0

I * might *하지만 표현식에서 해석/확장 할 변수가 없습니다. –

+0

이것은 특정 단어가 아닌'fooBML.Ibar'와 일치합니다. BML.I " – Kent

7

사람 페이지에서 grep -wF

을 시도 :

-w, --word-regexp 
        Select only those lines containing matches that form whole words. The 
        test is that the matching substring must either be at the beginning of 
        the line, or preceded by a non-word constituent character. Similarly, it 
        must be either at the end of the line or followed by a non-word 
        constituent character. Word-constituent characters are letters, digits, 
        and the underscore. 



-F, --fixed-strings 
       Interpret PATTERN as a list of fixed strings, separated by newlines, any 
       of which is to be matched. (-F is specified by POSIX.) 
4

fgrep을 사용합니다. grep -F

관련 문제