Skip to content
Advertisement

How do I add a numbered suffix at the end of my files using split on Linux BASH?

I’m using the split command in a Macbook and instead of getting numbers, I’m getting files such as output_aa, output_ab, output_ac, and what I need is output_1 , output_2, output_3, and so on.

Here’s the code I’m using, it’s on a .txt of a book (Harry Potter) and I’m trying to split it between chapters, however I need my endfiles to have the number corresponding to its chapter. split -p Chapter hp.txt hp_cap_

Advertisement

Answer

It’s not possible to do what you want to do with the macos version of the split command. Install coreutils

frank in ~
brew install coreutils

and use gsplit with the -d option

frank in ~ 
$ gsplit --help | grep -- "-d"
  -d                      use numeric suffixes starting at 0, not alphabetic
      --numeric-suffixes[=FROM]  same as -d, but allow setting the start value
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement