grep - deptno/deptno.github.io GitHub Wiki

grep

μ˜΅μ…˜

  • o : 라인이 μ•„λ‹Œ, 맀치된 λ‹¨μ–΄λ§Œ ν‘œμ‹œ
  • h : 헀더, 파일λͺ…등을 ν‘œμ‹œν•˜μ§€ μ•ŠμŒ
  • E : μ •κ·œν‘œν˜„μ‹ 맀치 μ‚¬μš©
  • n : 라인 ν‘œμ‹œ
  • r : νŠΉμ • 폴더 ν•˜μœ„λ‘œ 검색
  • color νŒ¨ν„΄μ— μΌμΉ˜ν•˜λŠ” 경우 컬러λ₯Ό λΆ€μ—¬, color=always 와 같이 μ“°λŠ” 경우 pipe λ₯Ό 톡해 less μ—μ„œ μ»¬λŸ¬μœ μ§€κ°€ κ°€λŠ₯함

λͺ¨λ“  라인 좜λ ₯ + ν•˜μ΄λΌμ΄νŠΈ

grep --color -E 'KEYWORD|$' -r [DIR]

ansi-color λ³€κ²½μ‹œμ—λŠ” env μ„€μ • ν•„μš” GREP_COLOR

GREP_COLOR='35;47' grep --color -E 'KEYWORD1|KEYWORD2|$' [FILENAME]

GREP_COLOR It is deprecated in favor of GREP_COLORS, but still supported. https://www.gnu.org/software/grep/manual/html_node/Environment-Variables.html

grep 을 λΆ„λ¦¬ν•΄μ„œ μ—¬λŸ¬λ²ˆ νŒŒμ΄ν”„λ‘œ μ—°κ²°ν•˜λŠ” 경우 각각 λ‹€λ₯Έ 색상 뢀여도 κ°€λŠ₯함

μžλ§€ν’ˆ

  • egrep - grep -E, νŒ¨ν„΄μ„ escape 없이 μ •κ·œμ‹μœΌλ‘œ μ²˜λ¦¬ν•˜λŠ” 경우
  • fgrep - grep -F, μ •κ·œμ‹μ„ μ‚¬μš©ν•˜μ§€ μ•Šκ³  μ²˜λ¦¬ν•˜λŠ” 경우

link