Grep

From 탱이의 잡동사니
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Overview

Linux/Unix 유틸리티 grep, egrep, fgrep, rgrep, zgrep 내용 정리.

Basic

Unix/Linux *grep 명령어는 패턴과 매칭되는 라인을 출력한다.

grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

Options

-e PATTERN, --regexp=PATTERN

입력된 패턴을 매칭패턴으로 사용한다. 여러개의 패턴을 지정할 수 있으며, 하이픈(-)과 같은 문자를 지정할 때도 사용할 수 있다. <source lang=bash> $ zgrep -e "AppleWebKit" -e "Trident" ./*.log.gz </source>

-i, --ignore-case

대/소문자를 가리지 않는다. <source lang=bash> $ grep -i -e "AppleWebKit" -e "Trident" ./*.log </source>

-v, --invert-match

반대로 매칭을 한다. 즉, 매칭되지 않는 문자열만을 표시한다.

<source lang=bash> $ zgrep -v -e "AppleWebKit" -e "Trident" ./*.log </source>