select-string.md 1.0 KB

Select-String

PowerShell์—์„œ ๋ฌธ์ž์—ด๊ณผ ํŒŒ์ผ์—์„œ ํ…์ŠคํŠธ๋ฅผ ์ฐพ์Šต๋‹ˆ๋‹ค. ์ฐธ๊ณ : ์ด ๋ช…๋ น์–ด๋Š” PowerShell์„ ํ†ตํ•ด์„œ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Select-String์„ UNIX์˜ grep์ด๋‚˜ Windows์˜ findstr.exe์™€ ์œ ์‚ฌํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋” ๋งŽ์€ ์ •๋ณด: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/select-string.

  • ํŒŒ์ผ ๋‚ด์—์„œ ํŒจํ„ด ๊ฒ€์ƒ‰:

Select-String -Path "{{๊ฒฝ๋กœ\๋Œ€์ƒ\ํŒŒ์ผ}}" -Pattern '{{๊ฒ€์ƒ‰_ํŒจํ„ด}}'

  • ์ •ํ™•ํ•œ ๋ฌธ์ž์—ด ๊ฒ€์ƒ‰ (์ •๊ทœ์‹ ๋น„ํ™œ์„ฑํ™”):

Select-String -SimpleMatch "{{์ •ํ™•ํ•œ_๋ฌธ์ž์—ด}}" {{๊ฒฝ๋กœ\๋Œ€์ƒ\ํŒŒ์ผ}}

  • ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ์˜ ๋ชจ๋“  .ext ํŒŒ์ผ์—์„œ ํŒจํ„ด ๊ฒ€์ƒ‰:

Select-String -Path "{{*.ext}}" -Pattern '{{๊ฒ€์ƒ‰_ํŒจํ„ด}}'

  • ํŒจํ„ด๊ณผ ์ผ์น˜ํ•˜๋Š” ์ค„ ์•ž๋’ค์˜ ์ง€์ •๋œ ์ค„ ์ˆ˜ ์บก์ฒ˜:

Select-String --Context {{2,3}} "{{๊ฒ€์ƒ‰_ํŒจํ„ด}}" {{๊ฒฝ๋กœ\๋Œ€์ƒ\ํŒŒ์ผ}}

  • stdin์—์„œ ํŒจํ„ด๊ณผ ์ผ์น˜ํ•˜์ง€ ์•Š๋Š” ์ค„ ๊ฒ€์ƒ‰:

Get-Content {{๊ฒฝ๋กœ\๋Œ€์ƒ\ํŒŒ์ผ}} | Select-String --NotMatch "{{๊ฒ€์ƒ‰_ํŒจํ„ด}}"