How to split files with numeric names?
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 from x89
to x9000
. I want the files to be named like that:
1.lst
2.lst
3.lst
...
Thanks.
linux split words
add a comment |
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 from x89
to x9000
. I want the files to be named like that:
1.lst
2.lst
3.lst
...
Thanks.
linux split words
add a comment |
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 from x89
to x9000
. I want the files to be named like that:
1.lst
2.lst
3.lst
...
Thanks.
linux split words
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 from x89
to x9000
. I want the files to be named like that:
1.lst
2.lst
3.lst
...
Thanks.
linux split words
linux split words
edited 2 days ago
Adel M.
asked 2 days ago
Adel M.Adel M.
112
112
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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'
With--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).
– Isaac
yesterday
add a comment |
Try this:
split --additional-suffix='.lst' -da3 -l 1024 list.lst ''
The reason for the jump to 9000
(for more than 89 parts) is that the default numeric length is 2
.
Change with the -a
option. To make sure the file numbering stay numeric (and is monotonic (always increase)) use a length that is longer than the maximum value that the possible number of splits.
$ split -a 3 -d -l1024 ./list.lst
$ ls
list.lst x009 x019 x029 x039 x049 x059 x069 x079 x089 x099 x109 x119
x000 x010 x020 x030 x040 x050 x060 x070 x080 x090 x100 x110 x120
x001 x011 x021 x031 x041 x051 x061 x071 x081 x091 x101 x111 x121
x002 x012 x022 x032 x042 x052 x062 x072 x082 x092 x102 x112 x122
x003 x013 x023 x033 x043 x053 x063 x073 x083 x093 x103 x113 x123
x004 x014 x024 x034 x044 x054 x064 x074 x084 x094 x104 x114 x124
x005 x015 x025 x035 x045 x055 x065 x075 x085 x095 x105 x115 x125
x006 x016 x026 x036 x046 x056 x066 x076 x086 x096 x106 x116 x126
x007 x017 x027 x037 x047 x057 x067 x077 x087 x097 x107 x117 x127
x008 x018 x028 x038 x048 x058 x068 x078 x088 x098 x108 x118
To change the x
, just change the PREFFIX
(default x
) (after the file name):
split -a 3 -d -l 1024 list.lst ''
Which will name the files 000
. To get a trailing .lst
, add the --additional-suffix='.lst'
option, in short, use this:
split --additional-suffix='.lst' -da3 -l 1024 list.lst ''
If you need the start numeric value to be 001
, use this:
split --additional-suffix='.lst' --numeric-suffixes=1 -a 3 -l 1024 list.lst ''
But no, there is no way to get the numeric values like 1,2,3,...,21,..,107 without renaming.
The renaming could resolve all issues in two steps with a simple loop:
split -l 1024 -d -a 8 list.lst
for f in x[0-9]*; do
mv "$f" "$((10#${f#x}+1)).lst"
done
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492732%2fhow-to-split-files-with-numeric-names%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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'
With--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).
– Isaac
yesterday
add a comment |
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'
With--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).
– Isaac
yesterday
add a comment |
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'
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'
answered 2 days ago
steeldriversteeldriver
34.8k35184
34.8k35184
With--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).
– Isaac
yesterday
add a comment |
With--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).
– Isaac
yesterday
With
--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).– Isaac
yesterday
With
--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).– Isaac
yesterday
add a comment |
Try this:
split --additional-suffix='.lst' -da3 -l 1024 list.lst ''
The reason for the jump to 9000
(for more than 89 parts) is that the default numeric length is 2
.
Change with the -a
option. To make sure the file numbering stay numeric (and is monotonic (always increase)) use a length that is longer than the maximum value that the possible number of splits.
$ split -a 3 -d -l1024 ./list.lst
$ ls
list.lst x009 x019 x029 x039 x049 x059 x069 x079 x089 x099 x109 x119
x000 x010 x020 x030 x040 x050 x060 x070 x080 x090 x100 x110 x120
x001 x011 x021 x031 x041 x051 x061 x071 x081 x091 x101 x111 x121
x002 x012 x022 x032 x042 x052 x062 x072 x082 x092 x102 x112 x122
x003 x013 x023 x033 x043 x053 x063 x073 x083 x093 x103 x113 x123
x004 x014 x024 x034 x044 x054 x064 x074 x084 x094 x104 x114 x124
x005 x015 x025 x035 x045 x055 x065 x075 x085 x095 x105 x115 x125
x006 x016 x026 x036 x046 x056 x066 x076 x086 x096 x106 x116 x126
x007 x017 x027 x037 x047 x057 x067 x077 x087 x097 x107 x117 x127
x008 x018 x028 x038 x048 x058 x068 x078 x088 x098 x108 x118
To change the x
, just change the PREFFIX
(default x
) (after the file name):
split -a 3 -d -l 1024 list.lst ''
Which will name the files 000
. To get a trailing .lst
, add the --additional-suffix='.lst'
option, in short, use this:
split --additional-suffix='.lst' -da3 -l 1024 list.lst ''
If you need the start numeric value to be 001
, use this:
split --additional-suffix='.lst' --numeric-suffixes=1 -a 3 -l 1024 list.lst ''
But no, there is no way to get the numeric values like 1,2,3,...,21,..,107 without renaming.
The renaming could resolve all issues in two steps with a simple loop:
split -l 1024 -d -a 8 list.lst
for f in x[0-9]*; do
mv "$f" "$((10#${f#x}+1)).lst"
done
add a comment |
Try this:
split --additional-suffix='.lst' -da3 -l 1024 list.lst ''
The reason for the jump to 9000
(for more than 89 parts) is that the default numeric length is 2
.
Change with the -a
option. To make sure the file numbering stay numeric (and is monotonic (always increase)) use a length that is longer than the maximum value that the possible number of splits.
$ split -a 3 -d -l1024 ./list.lst
$ ls
list.lst x009 x019 x029 x039 x049 x059 x069 x079 x089 x099 x109 x119
x000 x010 x020 x030 x040 x050 x060 x070 x080 x090 x100 x110 x120
x001 x011 x021 x031 x041 x051 x061 x071 x081 x091 x101 x111 x121
x002 x012 x022 x032 x042 x052 x062 x072 x082 x092 x102 x112 x122
x003 x013 x023 x033 x043 x053 x063 x073 x083 x093 x103 x113 x123
x004 x014 x024 x034 x044 x054 x064 x074 x084 x094 x104 x114 x124
x005 x015 x025 x035 x045 x055 x065 x075 x085 x095 x105 x115 x125
x006 x016 x026 x036 x046 x056 x066 x076 x086 x096 x106 x116 x126
x007 x017 x027 x037 x047 x057 x067 x077 x087 x097 x107 x117 x127
x008 x018 x028 x038 x048 x058 x068 x078 x088 x098 x108 x118
To change the x
, just change the PREFFIX
(default x
) (after the file name):
split -a 3 -d -l 1024 list.lst ''
Which will name the files 000
. To get a trailing .lst
, add the --additional-suffix='.lst'
option, in short, use this:
split --additional-suffix='.lst' -da3 -l 1024 list.lst ''
If you need the start numeric value to be 001
, use this:
split --additional-suffix='.lst' --numeric-suffixes=1 -a 3 -l 1024 list.lst ''
But no, there is no way to get the numeric values like 1,2,3,...,21,..,107 without renaming.
The renaming could resolve all issues in two steps with a simple loop:
split -l 1024 -d -a 8 list.lst
for f in x[0-9]*; do
mv "$f" "$((10#${f#x}+1)).lst"
done
add a comment |
Try this:
split --additional-suffix='.lst' -da3 -l 1024 list.lst ''
The reason for the jump to 9000
(for more than 89 parts) is that the default numeric length is 2
.
Change with the -a
option. To make sure the file numbering stay numeric (and is monotonic (always increase)) use a length that is longer than the maximum value that the possible number of splits.
$ split -a 3 -d -l1024 ./list.lst
$ ls
list.lst x009 x019 x029 x039 x049 x059 x069 x079 x089 x099 x109 x119
x000 x010 x020 x030 x040 x050 x060 x070 x080 x090 x100 x110 x120
x001 x011 x021 x031 x041 x051 x061 x071 x081 x091 x101 x111 x121
x002 x012 x022 x032 x042 x052 x062 x072 x082 x092 x102 x112 x122
x003 x013 x023 x033 x043 x053 x063 x073 x083 x093 x103 x113 x123
x004 x014 x024 x034 x044 x054 x064 x074 x084 x094 x104 x114 x124
x005 x015 x025 x035 x045 x055 x065 x075 x085 x095 x105 x115 x125
x006 x016 x026 x036 x046 x056 x066 x076 x086 x096 x106 x116 x126
x007 x017 x027 x037 x047 x057 x067 x077 x087 x097 x107 x117 x127
x008 x018 x028 x038 x048 x058 x068 x078 x088 x098 x108 x118
To change the x
, just change the PREFFIX
(default x
) (after the file name):
split -a 3 -d -l 1024 list.lst ''
Which will name the files 000
. To get a trailing .lst
, add the --additional-suffix='.lst'
option, in short, use this:
split --additional-suffix='.lst' -da3 -l 1024 list.lst ''
If you need the start numeric value to be 001
, use this:
split --additional-suffix='.lst' --numeric-suffixes=1 -a 3 -l 1024 list.lst ''
But no, there is no way to get the numeric values like 1,2,3,...,21,..,107 without renaming.
The renaming could resolve all issues in two steps with a simple loop:
split -l 1024 -d -a 8 list.lst
for f in x[0-9]*; do
mv "$f" "$((10#${f#x}+1)).lst"
done
Try this:
split --additional-suffix='.lst' -da3 -l 1024 list.lst ''
The reason for the jump to 9000
(for more than 89 parts) is that the default numeric length is 2
.
Change with the -a
option. To make sure the file numbering stay numeric (and is monotonic (always increase)) use a length that is longer than the maximum value that the possible number of splits.
$ split -a 3 -d -l1024 ./list.lst
$ ls
list.lst x009 x019 x029 x039 x049 x059 x069 x079 x089 x099 x109 x119
x000 x010 x020 x030 x040 x050 x060 x070 x080 x090 x100 x110 x120
x001 x011 x021 x031 x041 x051 x061 x071 x081 x091 x101 x111 x121
x002 x012 x022 x032 x042 x052 x062 x072 x082 x092 x102 x112 x122
x003 x013 x023 x033 x043 x053 x063 x073 x083 x093 x103 x113 x123
x004 x014 x024 x034 x044 x054 x064 x074 x084 x094 x104 x114 x124
x005 x015 x025 x035 x045 x055 x065 x075 x085 x095 x105 x115 x125
x006 x016 x026 x036 x046 x056 x066 x076 x086 x096 x106 x116 x126
x007 x017 x027 x037 x047 x057 x067 x077 x087 x097 x107 x117 x127
x008 x018 x028 x038 x048 x058 x068 x078 x088 x098 x108 x118
To change the x
, just change the PREFFIX
(default x
) (after the file name):
split -a 3 -d -l 1024 list.lst ''
Which will name the files 000
. To get a trailing .lst
, add the --additional-suffix='.lst'
option, in short, use this:
split --additional-suffix='.lst' -da3 -l 1024 list.lst ''
If you need the start numeric value to be 001
, use this:
split --additional-suffix='.lst' --numeric-suffixes=1 -a 3 -l 1024 list.lst ''
But no, there is no way to get the numeric values like 1,2,3,...,21,..,107 without renaming.
The renaming could resolve all issues in two steps with a simple loop:
split -l 1024 -d -a 8 list.lst
for f in x[0-9]*; do
mv "$f" "$((10#${f#x}+1)).lst"
done
edited yesterday
answered yesterday
IsaacIsaac
11.3k11651
11.3k11651
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492732%2fhow-to-split-files-with-numeric-names%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown