• 追加された行はこの色です。
  • 削除された行はこの色です。
* 文字列・ファイルのテキスト検索 - Select-String [#b98599f8]

** ファイルのテキスト検索 [#wd2b41ed]
 Select-String -Path "*.txt" -Pattern "hello"
Patternで指定する文字列はデフォルトで正規表現が使える。

** dirコマンドレットと組み合わせて再帰的に [#af2f208f]
 dir -Recurse -Filter "*.txt" | Select-String "hello"

** OR検索 [#d030170d]
 Select-String -Path "*.txt" -Pattern "hello","world"
"hello"または"world"がある行にマッチする。

** NOT検索 [#j7b088fe]
 Select-String -Path "*.txt" -NotMatch -Pattern "hello","world"
"hello"も"world"もない行にマッチする。

** マッチしたファイル名を取得 [#n54f0ab6]
 Select-String -Path "*.txt" -Pattern "hello" | Select-Object filename | Get-Unique 

** dirコマンドレット等のコマンドレットの出力結果オブジェクトを検索する [#ncf3183a]
 dir | Out-String -Stream | Select-String txt
Out-Stringを介してやる。


** 参考 [#w91e8459]
http://blogs.technet.com/b/heyscriptingguy/archive/2011/08/04/use-an-easy-powershell-command-to-search-files-for-information.aspx


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS