[Linux] grep λͺ λ Ήμ΄λ‘ νμΌ λ¬Έμ ν¨ν΄ κ²μνκΈ°
μμλλ©΄ νΈν grep λͺ λ Ήμ΄!!
grep μ νλ μ΄μμ νμΌμμ λ¬Έμ ν¨ν΄μ κ²μν λ μ¬μ©νλ€. κ·Έλ¦¬κ³ ν¨ν΄μ κ²μν κ²°κ³Όλ₯Ό μ νλ©΄μ μΆλ ₯νλ€.
grep option pattern filename
κ³Ό κ°μ νμμΌλ‘ μ΄λ€.
grep linux ccc
ccc λΌλ fileμμ linux λΌλ ν¨ν΄μ κ²μνλ λͺ λ Ήμ΄μ΄λ€. κ²°κ³Όλ λ€μκ³Ό κ°μ΄ νλ©΄μ μΆλ ₯ν΄μ€λ€.
grep -v pattern filename
ν¨ν΄μ μ μΈνκ³ κ²μνλ€.
grep -c pattern filename
κ²μ ν¨ν΄κ³Ό λ§€μΉλλ μ€ κ°μλ₯Ό μΆλ ₯νλ€.
grep -w pattern filename
λ¨μ΄ λ¨μλ‘ κ²μνλ€.
grep λͺ
λ Ήμ΄μμ μ κ·ννμ λ©νλ¬Έμλ νμ©ν μ μλ€.
^ : μ€μ μμ μ§μ
root@user-Aspire-E5-576:/home/user# grep ^hello ccc
hello hello world
hello my name is linux
$ : μ€μ λ§μ§λ§ μ§μ
root@user-Aspire-E5-576:/home/user# grep linux$ ccc
hello my name is linux
[] : ν λ¬Έμ λμΉ νκ³ κ²μ -> [hH]ello μ΄λ° μμΌλ‘ νκΈ°νλ€.
root@user-Aspire-E5-576:/home/user# grep [hH]ello ccc
hello hello world
hello my name is linux
Hello my name is Linux
[^] ν¨ν΄ μ€ μ μΈν λ¬Έμ
root@user-Aspire-E5-576:/home/user# grep ^[a-z] /etc/passwd
μλ¬Έμλ₯Ό μ μΈμμΌ°μΌλ―λ‘, λλ¬Έμμ μ«μκ° ν¬ν¨λ ν¨ν΄λ€μ νμν΄μ€λ€.