eightban's memo

残しておきたい記事をまとめてみました。このブログに書いてあるドキュメントやブログで配布しているファイルの使用によって発生するいかなる損害に対してもこのブログの管理者は責任を負いません。使用する場合は自己責任のもとに使用してください。

bat PowerShell  windows

PowerShell を使ってテキストファイルの先頭や末尾の行や途中の行を表示する方法Linux のHead Tail

更新日:

バッチファイル

powershell -command "Get-Content output1.txt -Head 2 | Out-Host"
powershell -command "Get-Content output1.txt -Tail 2 | Out-Host"

powershell -command "Get-Content output1.txt | Select-Object -First  2 | Out-Host"
powershell -command "Get-Content output1.txt | Select-Object -Last  2 | Out-Host"
powershell -command "Get-Content output1.txt | Select-Object -Skip 2 | Out-Host"     

配列を使って2行目から4行目を 先頭から最終行

powershell -command "(Get-Content output1.txt)[1..3] | Out-Host"
powershell -command "(Get-Content output1.txt)[0..-1] | Out-Host"

先頭の行を最終行に移動して出力

powershell -command " $contents = (Get-Content sendtext.txt)[0];Get-Content sendtext.txt | Select-Object -Skip 1 | ForEach-Object { Write-Host $_ } ;Write-Host $contents "

-bat, PowerShell , windows

Copyright© eightban's memo , 2024 All Rights Reserved Powered by STINGER.