-2

I have two question in split command:

1) How can we split a huge file in this format?

x0
x1
.
.
.
x10
.
.
.

2) How can we split a huge file in this format?

0
1
.
.
.
10
.
.
.
100
.
.
.

What I tried is not satisfactory because result is:

x00
x01
x02
.
.
.
x10
.
.
.
x100
.
.
.

Thank you

mpapec
  • 50,217
  • 8
  • 67
  • 127
MLSC
  • 5,872
  • 8
  • 55
  • 89

1 Answers1

2

First question:

>> ls
file
>> split -a 1 -d file
>> ls
file x0 x1 x2 x3 ...

However, you will get

split: output file suffixes exhausted

with this method if there would be more than 9 split files. You can use

>> split -d file
>> ls
file x00 x01 x02 ...

and then use rename:

>> rename 's/^x0/x/' x0*
>> ls
file x0 x1 x2 ...

Second question: Use

split -a 1 -d file ''

if you will have less then 10 split files. Otherwise, use

split -d file ''

and then

rename 's/^0//' 0*
timgeb
  • 76,762
  • 20
  • 123
  • 145