728x90
๋ฐ˜์‘ํ˜•

์‚ฌ์šฉ๋ฐฉ๋ฒ•

grep ๋ช…๋ น ๋’ค์— ์—ฌ๋Ÿฌ ๋ฌธ์ž์—ด, ํŒŒ์ผ ์ด๋ฆ„, ํ•ด๋‹น ๊ฒฝ๋กœ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค

 

์ž‘์€ ๋”ฐ์˜ดํ‘œ(' ')๋กœ ๋ฌถ๊ณ  ํŒŒ์ดํ”„( | )๋กœ ๊ตฌ๋ถ„ํ•˜๊ณ  ํŒŒ์ดํ”„์•ž์— ๋ฐฑ์Šฌ๋ž˜์‹œ( \ ) ์‚ฌ์šฉํ•จ

grep 'abc\|def' fileName_or_filePath

์ตœ๊ทผ์— ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ -E ์˜ต์…˜์„ ์‚ฌ์šฉํ•จ

-E ์˜ต์…˜์€ ํ™•์žฅ ์ •๊ทœ ํ‘œํ˜„์‹์œผ๋กœ ์ฒ˜๋ฆฌํ•จ

grep -E 'abc|def' fileName_or_filePath

grep์˜ ํ™•์žฅ๋ฒ„์ „์ธ egrep ๋˜ ๊ฐ€๋Šฅ

egrep 'abc|def' fileName_or_filePath

-e๋ฅผ ์—ฌ๋Ÿฌ๋ฒˆ ์‚ฌ์šฉ๋„ ๊ฐ€๋Šฅ

grep -e abc -e def fileName_or_filePath

 

grep, grep -E ๋ฐ egrep์˜ ์ฐจ์ด์ 

  1. grep์ด egrep ๋ณด๋‹ค ์˜ค๋ž˜๋œ ๋ฒ„์ „์ž„
  2. grep์€ ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด์„ ์ฐพ๊ณ , egrep์€ ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ฌธ์ž์—ด์„ ๋™์‹œ์— ์ฐพ์„ ์ˆ˜ ์žˆ์Œ
  3. grep์—์„œ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”ํƒ€๋ฌธ์ž ์ด์™ธ์— ์ถ”๊ฐ€ ์ •๊ทœํ‘œํ˜„์‹ ๋ฉ”ํƒ€๋ฌธ์ž๋ฅผ ์ง€์› ํ•จ

* 2021.11.29 ์ถ”๊ฐ€๋‚ด์šฉ

- egrep ์—์„œ ํŒŒ์ดํ”„๋กœ ๊ตฌ๋ถ„ํ•  ๋•Œ ๋„์–ด์“ฐ๊ธฐ ํ•˜์ง€๋ง๊ณ  ๋ถ™์—ฌ์„œ ์‚ฌ์šฉ.  ๋„์–ด ์“ฐ๋‹ˆ ์กฐํšŒ๋˜์ง€ ์•Š์•˜์Œ

 ์˜ˆ) ps -ef | egrep 'A|B|C|D' 

 

grep๊ณผ egrep์— ๋Œ€ํ•œ ์˜ต์…˜์ด๋‚˜ ์„ค๋ช…์€ ๋‚˜์ค‘์— ๋‹ค์‹œ ์ž‘์„ฑ


์ฐธ๊ณ ์‚ฌ์ดํŠธ

 

How to Grep for Multiple Strings, Patterns or Words

Use grep to search for multiple patterns or words in a file by following examples in this guide. The grep tool is one of the most famous command-line tools.

phoenixnap.com

 

728x90
๋ฐ˜์‘ํ˜•

+ Recent posts