mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-22 05:57:54 +00:00
parsort: Fixed -z when sorting files.
This commit is contained in:
parent
51f9bb2329
commit
63bfd1b9dc
13
src/parsort
13
src/parsort
|
@ -126,13 +126,14 @@ $Global::version = 20220622;
|
|||
if($opt::version) { version(); exit 0; }
|
||||
@Global::sortoptions = grep { ! /^-D$/ }
|
||||
shell_quote(@ARGV_before[0..($#ARGV_before-$#ARGV-1)]);
|
||||
#if($opt::zero_terminated) { $/ = "\0"; }
|
||||
|
||||
$ENV{'TMPDIR'} ||= "/tmp";
|
||||
|
||||
sub merge {
|
||||
# Input:
|
||||
# @cmd = commands to 'cat' (part of) a file
|
||||
# 'cat a' 'cat b' 'cat c' =>
|
||||
# sort -m <(sort -m <(cat a) <(cat b)) <(sort -m <(cat c))
|
||||
my @cmd = @_;
|
||||
chomp(@cmd);
|
||||
while($#cmd > 0) {
|
||||
|
@ -155,8 +156,11 @@ sub sort_files {
|
|||
# Input is files
|
||||
my @files = @_;
|
||||
# Let GNU Parallel generate the commands to read parts of files
|
||||
# The commands split at \n and there will be at least one for each CPU thread
|
||||
open(my $par,"-|",qw(parallel --pipepart --block -1 --dryrun -vv sort),
|
||||
# The commands split at \n (or \0)
|
||||
# and there will be at least one for each CPU thread
|
||||
my @subopt = $opt::zero_terminated ? qw(--recend "\0") : ();
|
||||
open(my $par,"-|",qw(parallel), @subopt,
|
||||
qw(--pipepart --block -1 --dryrun -vv sort),
|
||||
@Global::sortoptions, '::::', @files) || die;
|
||||
my @cmd = merge(<$par>);
|
||||
close $par;
|
||||
|
@ -181,7 +185,8 @@ sub sort_stdin {
|
|||
@cmd = merge(@cmd);
|
||||
if(fork) {
|
||||
} else {
|
||||
exec(qw(parallel -j),$numthreads,
|
||||
my @subopt = $opt::zero_terminated ? qw(--recend "\0") : ();
|
||||
exec(qw(parallel -j), $numthreads, @subopt,
|
||||
# 286k is the best mean value after testing 250..350
|
||||
qw(--block 286k --pipe --roundrobin cat > {} :::),@fifos);
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ par_tmpdir Should fail
|
|||
par_tmpdir parsort: Error: Tmpdir '/tmp/parsort dir' is not writable.
|
||||
par_tmpdir parsort: Error: Try 'chmod +w '/tmp/parsort dir''
|
||||
par_z ### parsort -z
|
||||
par_z 583c59e3574e550f6810d0ad20e7ab88 -
|
||||
par_z 507d17cd3d746cdeeccdb8ad11860181 -
|
||||
par_z 507d17cd3d746cdeeccdb8ad11860181 -
|
||||
par_z 507d17cd3d746cdeeccdb8ad11860181 -
|
||||
par_z 507d17cd3d746cdeeccdb8ad11860181 -
|
||||
|
|
Loading…
Reference in a new issue