mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-29 09:27:56 +00:00
parallel: --header will now parse the first line and you can use column names as {colname}.
This commit is contained in:
parent
71ff2d8701
commit
8c4b0ba4b9
37
src/parallel
37
src/parallel
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
||||||
|
|
||||||
# Copyright (C) 2007,2008,2009,2010,2011 Ole Tange and Free Software
|
# Copyright (C) 2007,2008,2009,2010,2011,2012 Ole Tange and Free Software
|
||||||
# Foundation, Inc.
|
# Foundation, Inc.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -53,6 +53,15 @@ if($Global::max_number_of_args) {
|
||||||
$number_of_args = 1;
|
$number_of_args = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $command = "";
|
||||||
|
if(@ARGV) {
|
||||||
|
if($Global::quoting) {
|
||||||
|
$command = shell_quote(@ARGV);
|
||||||
|
} else {
|
||||||
|
$command = join(" ", @ARGV);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my @fhlist;
|
my @fhlist;
|
||||||
@fhlist = map { open_or_exit($_) } @::opt_a;
|
@fhlist = map { open_or_exit($_) } @::opt_a;
|
||||||
if(not @fhlist) {
|
if(not @fhlist) {
|
||||||
|
@ -63,13 +72,19 @@ if($::opt_skip_first_line) {
|
||||||
my $fh = $fhlist[0];
|
my $fh = $fhlist[0];
|
||||||
<$fh>;
|
<$fh>;
|
||||||
}
|
}
|
||||||
|
if($::opt_header) {
|
||||||
my $command = "";
|
my $fh = $fhlist[0];
|
||||||
if(@ARGV) {
|
my $line = <$fh>;
|
||||||
if($Global::quoting) {
|
chomp($line);
|
||||||
$command = shell_quote(@ARGV);
|
# split with colsep or \t
|
||||||
} else {
|
# TODO should $header force $colsep = \t if undef?
|
||||||
$command = join(" ", @ARGV);
|
my $delimiter = $::opt_colsep;
|
||||||
|
my $id = 1;
|
||||||
|
::debug("Delimiter: '$delimiter'");
|
||||||
|
for my $s (split /$delimiter/o, $line) {
|
||||||
|
::debug("Colname: '$s'");
|
||||||
|
$command =~ s/\{$s\}/\{$id\}/g;
|
||||||
|
$id++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,6 +498,7 @@ sub options_hash {
|
||||||
"shebang|hashbang" => \$::opt_shebang,
|
"shebang|hashbang" => \$::opt_shebang,
|
||||||
"Y" => \$::opt_retired,
|
"Y" => \$::opt_retired,
|
||||||
"skip-first-line" => \$::opt_skip_first_line,
|
"skip-first-line" => \$::opt_skip_first_line,
|
||||||
|
"header" => \$::opt_header,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,7 +528,7 @@ sub get_options_from_array {
|
||||||
sub parse_options {
|
sub parse_options {
|
||||||
# Returns: N/A
|
# Returns: N/A
|
||||||
# Defaults:
|
# Defaults:
|
||||||
$Global::version = 20111222;
|
$Global::version = 20120107;
|
||||||
$Global::progname = 'parallel';
|
$Global::progname = 'parallel';
|
||||||
$Global::infinity = 2**31;
|
$Global::infinity = 2**31;
|
||||||
$Global::debug = 0;
|
$Global::debug = 0;
|
||||||
|
@ -583,6 +599,7 @@ sub parse_options {
|
||||||
if(defined $::opt_tmpdir) { $ENV{'TMPDIR'} = $::opt_tmpdir; }
|
if(defined $::opt_tmpdir) { $ENV{'TMPDIR'} = $::opt_tmpdir; }
|
||||||
if(defined $::opt_help) { die_usage(); }
|
if(defined $::opt_help) { die_usage(); }
|
||||||
if(defined $::opt_colsep) { $Global::trim = 'lr'; }
|
if(defined $::opt_colsep) { $Global::trim = 'lr'; }
|
||||||
|
if(defined $::opt_header) { $::opt_colsep = defined $::opt_colsep ? $::opt_colsep : "\t"; }
|
||||||
if(defined $::opt_trim) { $Global::trim = $::opt_trim; }
|
if(defined $::opt_trim) { $Global::trim = $::opt_trim; }
|
||||||
if(defined $::opt_arg_sep) { $Global::arg_sep = $::opt_arg_sep; }
|
if(defined $::opt_arg_sep) { $Global::arg_sep = $::opt_arg_sep; }
|
||||||
if(defined $::opt_arg_file_sep) { $Global::arg_file_sep = $::opt_arg_file_sep; }
|
if(defined $::opt_arg_file_sep) { $Global::arg_file_sep = $::opt_arg_file_sep; }
|
||||||
|
@ -1788,7 +1805,7 @@ sub version {
|
||||||
}
|
}
|
||||||
print join("\n",
|
print join("\n",
|
||||||
"GNU $Global::progname $Global::version",
|
"GNU $Global::progname $Global::version",
|
||||||
"Copyright (C) 2007,2008,2009,2010,2011 Ole Tange and Free Software Foundation, Inc.",
|
"Copyright (C) 2007,2008,2009,2010,2011,2012 Ole Tange and Free Software Foundation, Inc.",
|
||||||
"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>",
|
"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>",
|
||||||
"This is free software: you are free to change and redistribute it.",
|
"This is free software: you are free to change and redistribute it.",
|
||||||
"GNU $Global::progname comes with no warranty.",
|
"GNU $Global::progname comes with no warranty.",
|
||||||
|
|
|
@ -3145,7 +3145,7 @@ Copyright (C) 2007-10-18 Ole Tange, http://ole.tange.dk
|
||||||
|
|
||||||
Copyright (C) 2008,2009,2010 Ole Tange, http://ole.tange.dk
|
Copyright (C) 2008,2009,2010 Ole Tange, http://ole.tange.dk
|
||||||
|
|
||||||
Copyright (C) 2010,2011 Ole Tange, http://ole.tange.dk and Free
|
Copyright (C) 2010,2011,2012 Ole Tange, http://ole.tange.dk and Free
|
||||||
Software Foundation, Inc.
|
Software Foundation, Inc.
|
||||||
|
|
||||||
Parts of the manual concerning B<xargs> compatibility is inspired by
|
Parts of the manual concerning B<xargs> compatibility is inspired by
|
||||||
|
@ -3154,7 +3154,8 @@ the manual of B<xargs> from GNU findutils 4.4.2.
|
||||||
|
|
||||||
=head1 LICENSE
|
=head1 LICENSE
|
||||||
|
|
||||||
Copyright (C) 2007,2008,2009,2010,2011 Free Software Foundation, Inc.
|
Copyright (C) 2007,2008,2009,2010,2011,2012 Free Software Foundation,
|
||||||
|
Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -24,6 +24,8 @@ echo '### Test --resume --joblog followed by --resume --joblog';
|
||||||
parallel -j2 --resume --joblog /tmp/joblog2 sleep {} ::: 1.1 2.2 3.3 4.4;
|
parallel -j2 --resume --joblog /tmp/joblog2 sleep {} ::: 1.1 2.2 3.3 4.4;
|
||||||
cat /tmp/joblog2 | wc;
|
cat /tmp/joblog2 | wc;
|
||||||
rm -f /tmp/joblog2;
|
rm -f /tmp/joblog2;
|
||||||
|
echo '### Test --header';
|
||||||
|
printf "a\tb\n1\t2" | parallel --header echo {b} {a}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
echo '### Test --shellquote'
|
echo '### Test --shellquote'
|
||||||
|
|
|
@ -30,6 +30,8 @@ parallel: -H has been retired. Use --halt.
|
||||||
5 49 205
|
5 49 205
|
||||||
### Test --resume --joblog followed by --resume --joblog
|
### Test --resume --joblog followed by --resume --joblog
|
||||||
5 49 205
|
5 49 205
|
||||||
|
### Test --header
|
||||||
|
2 1
|
||||||
### Test --shellquote
|
### Test --shellquote
|
||||||
awk\ -v\ FS=\"\\\",\\\"\"\ \'\{print\ \$1,\ \$3,\ \$4,\ \$5,\ \$9,\ \$14\}\'\ \|\ grep\ -v\ \"\#\"\ \|\ sed\ -e\ \'1d\'\ -e\ \'s/\\\"//g\'\ -e\ \'s/\\/\\/\\//\\t/g\'\ \|\ cut\ -f1-6,11\ \|\ sed\ -e\ \'s/\\/\\//\\t/g\'\ -e\ \'s/\ /\\t/g
|
awk\ -v\ FS=\"\\\",\\\"\"\ \'\{print\ \$1,\ \$3,\ \$4,\ \$5,\ \$9,\ \$14\}\'\ \|\ grep\ -v\ \"\#\"\ \|\ sed\ -e\ \'1d\'\ -e\ \'s/\\\"//g\'\ -e\ \'s/\\/\\/\\//\\t/g\'\ \|\ cut\ -f1-6,11\ \|\ sed\ -e\ \'s/\\/\\//\\t/g\'\ -e\ \'s/\ /\\t/g
|
||||||
### Test make .deb package
|
### Test make .deb package
|
||||||
|
|
Loading…
Reference in a new issue