I use csplit to divide a complex file named file.docked.pdb to small files.

csplit -k -s -n 3 -f file.docked. file.docked.pdb '/^ENDMDL/+1' '{'7'}'

man csplit explains the following the code perfectly

       csplit - split a file into sections determined by context lines

       -k, --keep-files
              do not remove output files on errors

      -s, --quiet, --silent
              do not print counts of output file sizes
      -n, --digits=DIGITS
              use specified number of digits instead of 2

       -f, --prefix=PREFIX
              use PREFIX instead of 'xx'

   Each PATTERN may be:

              copy up to but not including a matching line

       {*}    repeat the previous pattern as many times as possible

My doubt is that the output files are starting to be named from file.docked.000 and extending forward

How to make the numbering start from file.docked.001???

If the tooling does not support this at all, please give a workaround.


1 Answer 1


The index of the first file output file is always 0 and there is no option to change the start index.

As a workaround, you could use a process substitution to print your pattern once before your data is output. This way this dummy line is split into file file.docked.000 which you can delete afterwards. Also increase the repeat pattern by one to get the desired number of output files.

csplit -k -s -n 3 -f file.docked. \
  <(echo "ENDMDL dummy, delete this file"; cat file.docked.pdb) '/^ENDMDL/+1' '{8}' &&
  rm file.docked.000

You must log in to answer this question.

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