Powershellでfindしてxargsしてgrepしたいときのやり方メモ。
確認環境
PS C:\Users\hoge> $PSVersionTable Name Value ---- ----- PSVersion 5.1.18362.752 minitty 2.9.6
やりたいこと
あるディレクトリに入っているファイルから、内容に特定の文字を含むファイル名を列挙する
Linuxでやる場合(今回はMinGWでやりました)
hoge@localhost MINGW64 ~/Desktop/20200806 $ ls a.txt b.txt c.txt hoge@localhost MINGW64 ~/Desktop/20200806 $ cat *txt apple beach child hoge@localhost MINGW64 ~/Desktop/20200806 $ find ./ -type f | xargs grep p ./a.txt:apple
Powershellでやる場合
PS C:\Users\hoge\Desktop\20200806> Get-ChildItem . | ?{ !$_.PSIsContainer}| %{ Select-String -Path $_.FullName -Pattern p} a.txt:1:apple # findはget-childitem+?{}(where-object) # xargsは%{} (foreach-object) # grepはselect-string