-1

there is a large file I split in bash. I am using

split -l 20000 -d "job1" "job1"

where job 1 is the input file - how can I change the naming of the output so that it produces job1_1,job1_2,gob1_3...,job1_12.....

is there an easy way to do that?

4

2 Answers 2

3

TL;DR Your command

split -l 20000 -d "job1" "job1"

puts 20000 lines per output file with a numeric suffix. The input is job1 and the output prefix is job1.

Therefore change the output prefix from job1 to job1_


Your command:

split -l 20000 -d job1 job1_

Avoid the leading zero:

split -l 20000 -d job1 job1_; rename 's/_0{1,}([0-9]+)/_$1/' job1_*

Avoid the leading zero and start the numeric suffix with 1:

split -l 20000 --numeric-suffixes=1 job1 job1_; rename 's/_0{1,}([0-9]+)/_$1/' job1_*

Example 1:

% split -l 20000 -d job1 job1_
% ls -og job1*                
-rw-rw-r-- 1 10000000 Mai 29 16:03 job1
-rw-rw-r-- 1  1540000 Mai 29 16:09 job1_00
-rw-rw-r-- 1  1540000 Mai 29 16:09 job1_01
-rw-rw-r-- 1  1540000 Mai 29 16:09 job1_02
-rw-rw-r-- 1  1540000 Mai 29 16:09 job1_03
-rw-rw-r-- 1  1540000 Mai 29 16:09 job1_04
-rw-rw-r-- 1  1540000 Mai 29 16:09 job1_05
-rw-rw-r-- 1   760000 Mai 29 16:09 job1_06

Example 2:

% split -l 10000 -d job1 job1_; rename 's/_0{1,}([0-9]+)/_$1/' job1_*
% ls -og job1*                                                       
-rw-rw-r-- 1 10000000 Mai 29 16:03 job1
-rw-rw-r-- 1   770000 Mai 29 16:23 job1_0
-rw-rw-r-- 1   770000 Mai 29 16:23 job1_1
-rw-rw-r-- 1   770000 Mai 29 16:23 job1_10
-rw-rw-r-- 1   770000 Mai 29 16:23 job1_11
-rw-rw-r-- 1   760000 Mai 29 16:23 job1_12
-rw-rw-r-- 1   770000 Mai 29 16:23 job1_2
-rw-rw-r-- 1   770000 Mai 29 16:23 job1_3
-rw-rw-r-- 1   770000 Mai 29 16:23 job1_4
-rw-rw-r-- 1   770000 Mai 29 16:23 job1_5
-rw-rw-r-- 1   770000 Mai 29 16:23 job1_6
-rw-rw-r-- 1   770000 Mai 29 16:23 job1_7
-rw-rw-r-- 1   770000 Mai 29 16:23 job1_8
-rw-rw-r-- 1   770000 Mai 29 16:23 job1_9

from man split

SYNOPSIS
       split [OPTION]... [INPUT [PREFIX]]

-d, --numeric-suffixes[=FROM]
              use numeric suffixes instead of alphabetic; FROM changes the start value (default 0)

-l, --lines=NUMBER
              put NUMBER lines per output file
0
1

If what you mean is to just add underscore then:

split -l 20000 -d "job1" "job1_"

You must log in to answer this question.

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