1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Powershellでワンライナー(テキストファイルを指定した行数で分割)

Posted at

はじめに

今はバッチで色々スクリプト組んでますが、やりたいことを簡単に実現させたいので(1行で貼りつけるだけで簡単にできるので楽)

ワンライナー

TextFileDivide.ps1
# sample.txtを100行毎に分割
$i=0; Get-Content sample.txt -ReadCount 100 | % { Write-Output $_ | Out-File -Encoding default sample$i.txt  ;$i++ }

注意
分割後のファイルは文字コードを指定しておかないとバッチ実行時にはまることが...(元ファイルがSJISで分割後のUnicode BOM付だったため、予期しない動きになって困った)

参考サイト

※関係ないサイトもあるのですが、後で使うことあるかもなので
◆[PowerShell] テキストファイルを指定した行数で分割する
 https://pasomaki.com/powershell-divide-text/
◆コマンドプロンプトから PowerShell を実行する
 https://qiita.com/ww24/items/7d52df13fef5bc54e149
◆PowerShellの引数展開に関する仕様まとめ
 https://qiita.com/nimzo6689/items/166ad623d95f80d9c53b
◆PowerShell でファイル内の文字列をワンライナーで置換する
 https://qiita.com/kaku10/items/7c28fa5ebc829efe301c
◆【Get-Date】PowerShellで現在の日付や時刻を取得する方法とは?フォーマットの変更は?
 https://cheshire-wara.com/powershell/ps-cmdlets/system-service/get-date/

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?