0
0

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 1 year has passed since last update.

MacでCSVファイルを分割

Posted at

デフォルトで入っているsplitコマンドでも分割できるが、使えるオプションが少ないのでgsplitコマンドをインストールして使用する。

gsplitコマンドのインストール

# gsplitコマンドをインストール
brew install coreutils

実行

# コマンド
gsplit -l ${分割する行数} -d -a ${連番の桁数} ${対象のファイル} ${分割後のファイル名} --additional-suffix=.${分割したファイルの拡張子}

# (例)test.csvを100行毎に「file_001.csv」の形式で分割する
gsplit -l 100 -d -a 3 test.csv file_ --additional-suffix=.csv

オプションの内容

オプション 内容
-l ${行数} 分割する行数
-d 分割後のファイルに連番をつける
-a ${連番の桁数}
--additional-suffix=.${拡張子} 分割したファイルの拡張子
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?