[clug] Thursday afternoon Perl/bash golf time
Tony Breeds
tony at bakeyournoodle.com
Thu Jun 11 02:43:45 MDT 2015
On Thu, Jun 11, 2015 at 04:26:19PM +1000, Andrew Janke wrote:
> I have a perl script, one of its jobs is to concatenate a large number
> of (binary) files together.
>
> I cheat and use the shell
>
> # create rawfile
> @args = ('cat', @catfiles, '>', "$opt{'tmpdir'}/all.raw");
> &do_cmd(join(' ', @args));
>
> (from: http://git.io/vIM2p)
>
> Of course now someone tried to use it with a large number of input
> files and it failed. So what to do?
>
> 1) for($i=0; $i<$#catfiles; $i+=100){
> system("cat @catfiles[$i..$i+99] /tmp/cat-$i");
> }
>
> # cat the bits.
>
>
> 2) Do it in bash
>
> for i in infiles.txt; do cat $i >> result; done
>
>
> 3) Do it in perl
Umm: perl -0pe '' * > ../all.raw ?
Is that shell or perl I don't know.
I could probably reduce that but I'm too lazy to dust off the perl from 15
years ago
Yours Tony.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/linux/attachments/20150611/8d487a59/attachment.pgp>
More information about the linux
mailing list