split

Split a file.

NAME
     split -- split a file into pieces

SYNOPSIS
     split [-a suffix_length] [-b byte_count[k|m]] [-l line_count]]
           [-p pattern] [file [name]]]

github

  • The file in jupyter notebook format on github is here.

google colaboratory

  • To run it in google colaboratory here split/split_nb.ipynb)

environment

The author’s OS is macOS, and the options are different from those of Linux and Unix commands.

In linux, you can specify the number of splits with the -n option, but as you can see in the man page, there is no such option in FreeBSD (the original OS of macOS).

But as you can see in man, FreeBSD (the original OS of macOS) does not have such an option. and %%bash in the first line.

!sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.6
BuildVersion: 18G2022
!bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Software Foundation, Inc.

Example usage

Usually used with the following typical options.

Typical options

  • b : number of bytes to split
  • l : number of lines to split
  • a : number of characters to use for prefix
%%bash
echo -e "1\n2\n3\n4\n5\n6\n7\n8\n9\n10" > temp
cat temp

split -l 2 -a 3 temp prefix_
echo -e "\n<file list>"
ls | grep -v split

echo -e "\fn<prefix_aaa file content>"
cat prefix_aaa
1
2
3
4
Five.
Six.
Seven.
8
9
10

<file list
prefix_aaa
prefix_aab
prefix_aac
prefix_aad
prefix_aae
temp

<prefix_aaa file content
1
2