2014년 12월 14일 일요일

GREP 필수 사용법 정리 & Windows GREP

GREP은 텍스트 검색 기능을 가진 명령어이다. linux나 Unix에서는 기본으로 있는 명령어이지만 windows에서는 별도로 설치해야만 사용이 가능하다.

많은 소스를 가지고 소스내에서 검색하는 기능을 가진 프로그램으로는 source insight가 있으며, opengrok을 설치해서도 소스 검색이 가능하지만 해당 프로그램을 설치하는것은 무거운 상황이 될 수 있다. 따라서 프로그래머라면 기본적으로 grep의 기본 명령어 정도는 알고 있으면 편하다.

  • Windows 에서 GREP 설치

http://www.wingrep.com/ 여기껀 별로다. 설치하지 말자. 기본적으로 window창으로 동작한다.
http://gnuwin32.sourceforge.net/packages/grep.htm 여기 것을 설치 하도록 합니다.
설치 link는 아래보면 Requirements 에 있는 Setup program 링크를 눌러서 설치하도록 합니다. ( download 링크쪽은 일부 dll이 포함이 안되어있어 설정해주기가 귀찮습니다.)

RequirementsRequirements for running applications, excluding external ones such as msvcrt.dll, perl, etc, are included in the Setup program and the dependencies zip file.
  • Win32, i.e. MS-Windows 95 / 98 / ME / NT / 2000 / XP / 2003 / Vista / 2008 with msvcrt.dll and msvcp60.dll. If msvcrt.dll or msvcp60.dll is not in your Windows/System folder, get them from Microsoft, or (msvcrt.dll only) by installing Internet Explorer 4.0 or higher.

Setup program << Windows에서 GREP 사용하려면 여기 링크 사용하세요

  • PATH 등록하기

어디에서나 grep 명령을 치면 동작해야 하므로
C:\Program Files (x86)\GnuWin32\bin (64 bit 환경)또는 C:\Program Files\GnuWin32\bin (32bit 환경)경로를 PATH에 추가해 주도록 합니다.
둘중에 어떤 경로인지는 설치할때 자신이 설정한 경로가 됩니다.

제어판->시스템 보안 -> 시스템 -> 고급 시스템 설정 -> 환경 변수 -> 시스템 변수(Path항목 선택) -> 편집 -> 마지막에 ";C:\Program Files (x86)\GnuWin32\bin" 추가
각각의 항목은 ; (세미 콜론)으로 구분 됩니다.


  • 기본 사용법

사용법: grep [옵션]... 패턴 [파일]...


  • 현재 폴더 내에서 있는 모든 파일(예:*)에서 원하는 문자열(예:init) 찾기

grep init *

D:\download\encog-examples-3.2.0-release\encog-examples-3.2.0>grep init *
grep: .settings: Is a directory
grep: apidocs: Is a directory
build.xml:  <target name="init">
build.xml:  <target name="compile" depends="init"
grep: lib: Is a directory
grep: src: Is a directory

  • GREP 하위 모든 폴더 내에서 특정 문자열(예:init) 있는지 검색하기

grep -r init *  


  • GREP 하위 모든 폴더 내에서 특정 파일에서 특정 문자열 있는지 검색하기

grep -r init *.xml  (하위폴더 xml 파일에서 검색)

D:\download\encog-examples-3.2.0-release\encog-examples-3.2.0>grep -r init *.xml

build.xml:  <target name="init">
build.xml:  <target name="compile" depends="init"


  • GREP 하위 모든 폴더 내에서 특정 파일에서 특정 문자열(단어) 있는지 검색하기
grep -r -w ini *.xml (-w 사용)

D:\download\encog-examples-3.2.0-release\encog-examples-3.2.0>grep -r ini *.xml
build.xml:  <target name="init">
build.xml:  <target name="compile" depends="init"

D:\download\encog-examples-3.2.0-release\encog-examples-3.2.0>grep -r -w ini *.x
ml

D:\download\encog-examples-3.2.0-release\encog-examples-3.2.0>grep -r -w init *.
xml
build.xml:  <target name="init">
build.xml:  <target name="compile" depends="init"

댓글 없음:

댓글 쓰기