리눅스 쉘 스크립트 학습 - 명령어(grep)

Purple·2022년 10월 13일
0

리눅스 쉘 스크립트

목록 보기
29/53

grep

  • 다음과 같은, 이름이 쭉적힌 president.txt가 있다.
  • . : Dot. Matches any character excpet line breaks.
  • "*" : Quantifier. Match 0 or more of the preceding token.

grep -c

  • count 하는 옵션이다.
  • 다음과 같이 사용하면, 빈줄을 찾을 count 할 수 있다.
  • ^ : Beginning. Matches the beginning of the string, or the begging of a line if the multiline flag (m) is enabled.
  • $ : End. Matches the end of the string, or the end of a line if the multiline flag(m) is enabled.

grep -o

  • only에 해당하는 옵션으로, 해당하는 부분만을 출력해주는 옵션이다.

grep '\|'

  • | : 또는 논리가 들어간 정규패턴 매칭의 유형이다.
  • 앞에 백슬래시는 escape 문자이다.

egrep '|'

  • egrep을 사용하면, 위와 같이 escape문자를 붙이지 않아도 된다.

grep -E '^[[:digit:]]'

  • -E : PATTERN is an extended regualr expression.
  • posix 표현을 사용한 정규 패턴 매칭
  • 다음과 같은 사용도 가능하다.

grep -i

  • 대소문자 관계없이 찾으라느 옵션이다.
  • 맨 앞의 ^ : Beginning. Mtaches the beginning of the string, or the beginning of a line if the multiline flag (m) is enabled.
  • [^] : Negated set. Match any character that is not in the set.

grep -v

  • 지정한 패턴이 발견되지 않는 것을 찾을 때 사용하는 옵션이다.

grep -B -A

  • -B : Before
  • -A : After

grep -n

  • -n : 파일 내에서 행 번호를 함께 출력한다.

fgrep

  • 일반 검색에 해당하는 find 명령어와 비슷하다.
  • 따라서 ''안에 들어가는 문자들은 모두 일반문자로 해석된다.
profile
안녕하세요.

0개의 댓글