UNIX/Redhat

grep --color 옵션을 줘서 글자 색 출력

99iberty 2013. 7. 29. 09:57

 

 

http://it.gilbird.com/index.php?mid=textyle&category=8260&document_srl=8811

 

 

§ 1. 개요

grep으로 나온 결과물에서 키워드에 컬러를 넣는 방법을 알아보자.

§ 2. --color 옵션

grep에 --color 옵션을 주면 해당 키워드가 하일라이트 되어 나온다

$ cat test.txt | grep --color abc
abcdef


그런데 more를 같이 쓰면 단색으로 나온다.

$ cat test.txt | grep --color abc | more
abcdef


이럴때는 --color=always 옵션을 주면 된다.

$ cat test.txt | grep --color=always abc | more
abcdef

§ 3. 컬러 변경

grep 컬러를 변경하고 싶다면 다음과 같이 환경 변수값을 지정하면 된다.

export GREP_COLOR=34