This command does not work in GNU Coreutils split, split of Cern Linux 5 (Redhat) and BSD (Apple Yosemite 10.10.3):

split -p'\0' input.txt

where input.txt is masi\0hello\0world. Some comments about the versions follow:

  • I do split -p'\0' input.txt in BSD Split but I get nothing as output in OSX Yosemite 10.10.3, GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14).
  • I do echo 'masi\0hello' | split -p'\\0' in split 5.97 GNU 2012 in CERN Linux 5 (Redhat). Output split: unrecognized option --p\\0'.
  • no option -p in GNU Coreutils split

I have forgot where I successfully used the option -p with split. Which version of split does support the flag -p?

  • 1
    \0 is literal string or NULL byte?
    – cuonglm
    Commented Jun 24, 2015 at 13:40
  • 1
    -p see pattern as extended regex, you can try -p'\\0'.
    – cuonglm
    Commented Jun 25, 2015 at 7:25
  • 1
    What shell did you use? Redhat won't work, split from GNU coreutils doesn't have -p option.
    – cuonglm
    Commented Jun 25, 2015 at 8:02
  • @cuonglm I have tried Split in CERN Linux 5 (which I think is GNU from Freeman), BSD Split and GNU Split from coreutils. Updated the pieces of information in the body. Commented Jun 29, 2015 at 18:39

1 Answer 1


The -p option in Mac OS X will split when a line matches \0. So you need to provide newlines around the \0. Sorry I don't have a solution for you. You are using the tool wrong. You might look into perl. Translate your NUL characters to CTRL-A, add the newlines and then use split with -p'^A' (CTRL-V CTRL-A). For example, you can do something like:

cat input.txt |perl -p -e 's/\0/\n^A\n/g'| split -p ^A

Where ^A is CTRL-A, but I'm not sure that matters.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .