parallel: --header will now parse the first line and you can use column names as {colname}.

This commit is contained in:
Ole Tange 2012-01-07 04:17:13 +01:00
parent 71ff2d8701
commit 8c4b0ba4b9
4 changed files with 34 additions and 12 deletions

View file

@ -1,6 +1,6 @@
#!/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.
#
# 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;
}
my $command = "";
if(@ARGV) {
if($Global::quoting) {
$command = shell_quote(@ARGV);
} else {
$command = join(" ", @ARGV);
}
}
my @fhlist;
@fhlist = map { open_or_exit($_) } @::opt_a;
if(not @fhlist) {
@ -63,13 +72,19 @@ if($::opt_skip_first_line) {
my $fh = $fhlist[0];
<$fh>;
}
my $command = "";
if(@ARGV) {
if($Global::quoting) {
$command = shell_quote(@ARGV);
} else {
$command = join(" ", @ARGV);
if($::opt_header) {
my $fh = $fhlist[0];
my $line = <$fh>;
chomp($line);
# split with colsep or \t
# TODO should $header force $colsep = \t if undef?
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,
"Y" => \$::opt_retired,
"skip-first-line" => \$::opt_skip_first_line,
"header" => \$::opt_header,
);
}
@ -512,7 +528,7 @@ sub get_options_from_array {
sub parse_options {
# Returns: N/A
# Defaults:
$Global::version = 20111222;
$Global::version = 20120107;
$Global::progname = 'parallel';
$Global::infinity = 2**31;
$Global::debug = 0;
@ -583,6 +599,7 @@ sub parse_options {
if(defined $::opt_tmpdir) { $ENV{'TMPDIR'} = $::opt_tmpdir; }
if(defined $::opt_help) { die_usage(); }
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_arg_sep) { $Global::arg_sep = $::opt_arg_sep; }
if(defined $::opt_arg_file_sep) { $Global::arg_file_sep = $::opt_arg_file_sep; }
@ -1788,7 +1805,7 @@ sub version {
}
print join("\n",
"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>",
"This is free software: you are free to change and redistribute it.",
"GNU $Global::progname comes with no warranty.",

View file

@ -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) 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.
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
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
it under the terms of the GNU General Public License as published by

View file

@ -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;
cat /tmp/joblog2 | wc;
rm -f /tmp/joblog2;
echo '### Test --header';
printf "a\tb\n1\t2" | parallel --header echo {b} {a}
EOF
echo '### Test --shellquote'

View file

@ -30,6 +30,8 @@ parallel: -H has been retired. Use --halt.
5 49 205
### Test --resume --joblog followed by --resume --joblog
5 49 205
### Test --header
2 1
### 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
### Test make .deb package