What is the best, python or bash for selectively concatenating lots of files?

Posted by Werner on Stack Overflow See other posts from Stack Overflow or by Werner
Published on 2010-03-12T17:47:59Z Indexed on 2010/03/12 18:07 UTC
Read the original article Hit count: 133

Filed under:
|

Hi,

I have around 20000 files coming from the output of some program, and their names follow the format:

data1.txt
data2.txt
...
data99.txt
data100.txt
...
data999.txt
data1000.txt
...
data20000.txt

I would like to write a script that gets as input argument the number N. Then it makes blocks of N concatenated files, so if N=5, it would make the following new files:

data_new_1.txt: it would contain (concatenated) data1.txt to data5.txt (like cat data1.txt data2.txt ...> data_new_1.txt ) data_new_2.txt: it would contain (concatenated) data6.txt to data10.txt .....

I wonder what do you think would be the best approach to do this, whether bash, python or another one like awk, perl, etc.

The best approach I mean in terms of simplest code.

Thanks

© Stack Overflow or respective owner

Related posts about bash

Related posts about python