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

2024年4月24日

バッチファイル

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

Posted by eightban