[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
์๋ฌธ์๋ฅผ ์ ์ธ์์ผฐ์ผ๋ฏ๋ก, ๋๋ฌธ์์ ์ซ์๊ฐ ํฌํจ๋ ํจํด๋ค์ ํ์ํด์ค๋ค.