In GNU/Linux in order to split file into 4 equal chunks we can do something like:
split temp -n 4 PREFIX_
But seems like the macOS' BSD version of split
utility doesn't have -n
option.
What would be the analog of GNU split command in macOS?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIn GNU/Linux in order to split file into 4 equal chunks we can do something like:
split temp -n 4 PREFIX_
But seems like the macOS' BSD version of split
utility doesn't have -n
option.
What would be the analog of GNU split command in macOS?
Unfortunately MacOS contains crippled BSD versions of coreutils. Head also does not support negative byte counts, while it's GNU analog allows to do something like head -c -1
.
I ended up installing GNU version of coreutils on MacOS:
brew install coreutils
This installs all the coreutils including split and head with prefix g
. So now I can do:
gsplit ${file} -n 4 PREFIX_
And
ghead -c -1 ${file}
You could find the size of the file and divide it by 4 and use MacOS's split -b
on the number of bytes instead. I don't have a way to test this, but loosely:
#!/bin/bash
file=myfile
size=$(stat -f '%z' "$myfile")
let part=size/4
[ "$part" = 0 ] && part=1
split -b "$part" "$myfile" ...
I don't know what happens when the size is under 4 bytes and you say split -b 0
, so make it 1.
See the man pages split and stat.