강좌
클라우드/리눅스에 관한 강좌입니다.
리눅스 분류

지정된 파일 내에서 특정문자 찾기

작성자 정보

  • 관리자 작성
  • 작성일

컨텐츠 정보

본문

지정된 파일 내에서 특정문자 찾기






 

지정된 파일 내에서 특정문자(문자열)를 찾기 위한 기본 사용형식은 다음과 같습니다.

 

 

 

 


사용형식 :  grep  찾을 문자열  대상파일

 

아래의 예는 apache.txt라는 파일 내에서 “apache”라는 문자를 찾은 예입니다.

 

 

 

 먼저 cat으로 apache.txt파일의 내용을 확인하였습니다.

 

 

 

 그리고 grep으로 “apache”라는 문자열이 들어가 있는 행을 검색하였습니다.

 

 

 

 결과 apache.txt 라는 파일 내 두개의 행에서 apache라는 문자가 포함되어있음을 알 수 있으며  또한 포함된 행을 출력해 줍니다.

 

 

 

 

 

[root@su250 ~]# cat apache.txt

This directory holds Apache 2.0 module-specific configuration files;

any files in this directory which have the ".conf" extension will be

processed as Apache configuration files in apache.

 

Files are processed in alphabetical order apache, so if using configuration

directives which depend on, say, mod_perl being loaded, ensure that

these are placed in a filename later in the sort order than "perl.conf".

 

[root@su250 ~]# grep apache apache.txt

processed as Apache configuration files in apache.

Files are processed in alphabetical order apache, so if using configuration

[root@su250 ~]#

 

위의 예는 지정된 파일에서 특정문자열을 찾는 grep명령어의 가장 기본적인 사용법입니다.

 

 

 

 

 

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,037 명
  • 현재 강좌수 :  35,806 개
  • 현재 접속자 :  149 명