diff --git a/src/parallel b/src/parallel index 14388253..bea103e1 100755 --- a/src/parallel +++ b/src/parallel @@ -398,6 +398,7 @@ sub options_hash { "shellquote|shell_quote|shell-quote" => \$::opt_shellquote, "nice=i" => \$::opt_nice, "timeout=i" => \$::opt_timeout, + "tag" => \$::opt_tag, "onall" => \$::opt_onall, "nonall" => \$::opt_nonall, "sshlogin|S=s" => \@::opt_sshlogin, @@ -1678,6 +1679,11 @@ sub usage { "--recstart str Record start separator for --pipe.", "", "See 'man $Global::progname' for details", + "", + "When using GNU Parallel for a publication please cite:", + "", + "O. Tange (2011): GNU Parallel - The Command-Line Power Tool,", + ";login: The USENIX Magazine, February 2011:42-47.", ""); } @@ -3461,21 +3467,36 @@ sub print { if($Global::debug) { print STDERR "ERR:\n"; } - my $buf; - while(sysread($err,$buf,1000_000)) { - print STDERR $buf; + if($::opt_tag) { + my $tag = $self->{'commandline'}->args_as_string(); + while(<$err>) { + print STDERR $tag,"\t",$_; + } + } else { + my $buf; + while(sysread($err,$buf,1000_000)) { + print STDERR $buf; + } } flush STDERR; if($::opt_files) { print STDOUT $self->{'stdoutfilename'},"\n"; } else { + my $buf; seek $out, 0, 0; if($Global::debug) { print STDOUT "OUT:\n"; } - while(sysread($out,$buf,1000_000)) { - print STDOUT $buf; + if($::opt_tag) { + my $tag = $self->{'commandline'}->args_as_string(); + while(<$out>) { + print STDOUT $tag,"\t",$_; + } + } else { + while(sysread($out,$buf,1000_000)) { + print STDOUT $buf; + } } flush STDOUT; ::debug("<{'arg_list'}}+1; } +sub args_as_string { + # Returns: + # all unmodified arguments joined with ' ' (similar to {}) + my $self = shift; + return (join " ", map { $_->orig() } + map { @$_ } @{$self->{'arg_list'}}); +} + sub len { # The length of the command line with args substituted my $self = shift; diff --git a/src/parallel.pod b/src/parallel.pod index 02a8489d..5a1cd9f1 100644 --- a/src/parallel.pod +++ b/src/parallel.pod @@ -1148,6 +1148,12 @@ and it will open a tty for the job. When the job is done, the next job will get the tty. +=item B<--tag> + +Tag lines with arguments. Each output line will be prepended with the +arguments and TAB (\t). + + =item B<--tmpdir> I Directory for temporary files. GNU B normally buffers output diff --git a/testsuite/tests-to-run/test20.sh b/testsuite/tests-to-run/test20.sh index ab0b2ad2..d53e92ac 100644 --- a/testsuite/tests-to-run/test20.sh +++ b/testsuite/tests-to-run/test20.sh @@ -12,4 +12,11 @@ echo '### Test --use-cpus-instead-of-cores' echo 'Cores should complete first on machines with less than 4 physical CPUs' wait +echo '### Test --tag ::: a ::: b' +stdout parallel -k --tag -j1 echo stderr-{.} ">&2;" echo stdout-{} ::: a ::: b +echo '### Test --tag ::: a b' +stdout parallel -k --tag -j1 echo stderr-{.} ">&2;" echo stdout-{} ::: a b + +echo '### Test --tag -X ::: a b' +stdout parallel -k --tag -X -j1 echo stderr-{.} ">&2;" echo stdout-{} ::: a b diff --git a/testsuite/wanted-results/test20 b/testsuite/wanted-results/test20 index e80c2ed8..b5bfdfde 100644 --- a/testsuite/wanted-results/test20 +++ b/testsuite/wanted-results/test20 @@ -6,3 +6,14 @@ Cores should complete first on machines with less than 4 physical CPUs cores done CPUs done +### Test --tag ::: a ::: b +a b stderr-a b +a b stdout-a b +### Test --tag ::: a b +a stderr-a +a stdout-a +b stderr-b +b stdout-b +### Test --tag -X ::: a b +a b stderr-a stderr-b +a b stdout-a stdout-b