How to split files with numeric names?
5,519
At least with the GNU Coreutils version of split
, you can do it as follows:
split -l300 --numeric-suffixes=1 --suffix-length=1 --additional-suffix=".lst" file ""
Note the use of ""
to specify an empty prefix (the xa
part of the default filename) and the use of --numeric-suffixes
in place of -d
(which always starts from 0).
Note also that this assumes that the file to be split contains no more than 9 x 300 lines - otherwise split
will complain that output file suffixes exhausted
Ex.
$ split -l300 --numeric-suffixes=1 --suffix-length=1 --additional-suffix=".lst" --verbose file ""
creating file '1.lst'
creating file '2.lst'
creating file '3.lst'
creating file '4.lst'
Related videos on Youtube
Author by
Adel M.
Updated on September 18, 2022Comments
-
Adel M. over 1 year
I'm trying to split text file into files of 1024 lines, so I ran
split
with the-d
switch:split -d -l 300 ./list.lst
I get some weird names: they start with
x
and the file names jump fromx89
tox9000
. I want the files to be named like that:1.lst 2.lst 3.lst ...
Thanks.
-
done over 5 yearsWith
--suffix-length=1
it is only possible to create 9 parts (1-9). The user is creating more than 89 parts (because he reports filenames as x9000). So, length should be at least 3 (or more).