2011-09-26 4 views
2

은 내가 다음과 같이 containtent와 filw 한 :파일에서 패턴을 검색하고 터미널에 줄을 표시하는 방법은 무엇입니까?

pid 4565 Process: /my/name/is/4678 +34787[d][email protected]##$ 
pid 33453 Process: /my/name/is/4678 +34787[d][email protected]##werwer$ 
pid 3453345 Process: /my/name/is/4678 +3478[7][email protected]##$ 
pid 12335 Process: /my/name/is/4678 +3478se[r][email protected]##$ 

내가 "34787 [D] sfh888dfsj @ ## werwer $"이 패턴을 contaning 라인을 필요로하고 터미널에서 그 라인을 전부 얻을 필요하거나 재 NE 수 있습니다 다른 파일. 어떠한 제안? 미리 감사드립니다.

+1

'man grep'? 그게 일할 수 있을까? ' –

+0

@ALL 지원해 주셔서 감사합니다. -a 옵션을 사용하여 필요한 결과를 얻었습니다. 내 파일이 바이너리 파일이므로 패턴을 검색하려면 다음과 같이 -a 옵션이 필요합니다. grep -a "my_pattern"file.log – BSalunke

답변

1

사용 그렙 (일명 fgrep) :

grep -F '+34787[d][email protected]##werwer$' /path/to/my/file 

실행 man grep 더 많은 것을 배울 수 있습니다.

grep -F '+34787[d][email protected]##werwer$' /path/to/my/file > /path/to/my/output 

실행 man sh 또는 man bash 및 리디렉션에 대해 읽어 :

대신 표준 출력의 일부 출력 파일로 리디렉션해야하는 경우.

0

grep/awk/sed ... 많은 도구가이를 수행 할 수 있습니다. 그렙 예 : 고정 문자열 모드

kent$ echo "pid 4565 Process: /my/name/is/4678 +34787[d][email protected]##$ 
    pid 33453 Process: /my/name/is/4678 +34787[d][email protected]##werwer$ 
    pid 3453345 Process: /my/name/is/4678 +3478[7][email protected]##$ 
    pid 12335 Process: /my/name/is/4678 +3478se[r][email protected]##$"|grep '\+34787\[d\][email protected]##werwer\$' 

    pid 33453 Process: /my/name/is/4678 +34787[d][email protected]##werwer$ 
관련 문제