리눅스/Bash
[bash][grep] 문자열과 일치하는 내용을 가지는 파일 확인 하기(grep 사용)
hs_seo
2017. 4. 10. 11:21
특정 문자열과 일치하는 내용을 가지고 있는 파일을 확인하고 싶을 때
grep 을 이용하여 내용을 확인할 수 있다.
-L, --files-without-match
Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.
-l, --files-with-matches
Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. (-l is specified by POSIX.)
<문자열과 일치하는 파일 확인>
> echo a > a.txt
> echo b > b.txt
<파일 확인>
grep [-l][-L] 문자열 파일위치
-l : 일치하는 파일
-L : 일치하지 않는 파일
> grep -l a *
a.txt
> grep -L a *
b.txt
<문자열과 일치하는 파일의 라인 번호 확인>
> cat a.txt | grep -n a
1:a
반응형