mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-22 05:57:54 +00:00
Example for manual. Bug fix. More unittests.
This commit is contained in:
parent
ab4133d44d
commit
fcbfd19220
|
@ -1,22 +1,41 @@
|
||||||
|
|
||||||
example with colsep
|
|
||||||
|
# Gzip all files in parallel
|
||||||
|
parallel gzip ::: *
|
||||||
|
|
||||||
|
# Convert *.wav to *.mp3 using LAME running one process per CPU core:
|
||||||
|
parallel -j+0 lame {} -o {.}.mp3 ::: *.wav
|
||||||
|
|
||||||
|
# Make an uncompressed version of all *.gz
|
||||||
|
parallel zcat {} ">"{.} ::: *.gz
|
||||||
|
|
||||||
|
# Recompress all .gz files using bzip2 running 1 job per CPU core:
|
||||||
|
find . -name '*.gz' | parallel -j+0 "zcat {} | bzip2 >{.}.bz2 && rm {}"
|
||||||
|
|
||||||
|
# Create a directory for each zip-file and unzip it in that dir
|
||||||
|
parallel 'mkdir {.}; cd {.}; unzip ../{}' ::: *.zip
|
||||||
|
|
||||||
|
# Convert all *.mp3 in subdirs to *.ogg running
|
||||||
|
# one process per CPU core on local computer and server2
|
||||||
|
find . -name '*.mp3' | parallel --trc {.}.ogg -j+0 -S server2,: \
|
||||||
|
'mpg321 -w - {} | oggenc -q0 - -o {.}.ogg'
|
||||||
|
|
||||||
|
# Run mycmd on column 1-3 of each row of TAB separated values
|
||||||
|
parallel -a table_file.tsv --colsep '\t' mycmd -o {2} {3} -i {1}
|
||||||
|
|
||||||
|
# Run traceroute in parallel, but keep the output order the same
|
||||||
|
parallel -k traceroute ::: foss.org.my debian.org freenetproject.org
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Unittest: --colsep + multiple -a
|
Unittest: --colsep + multiple -a
|
||||||
|
|
||||||
|
|
||||||
Unittest: eof string on :::
|
|
||||||
Unittest: quoting efter colsplit
|
|
||||||
|
|
||||||
Better screenshot on http://freshmeat.net/projects/parallel
|
|
||||||
Better examples.
|
|
||||||
Size: 640x480
|
|
||||||
|
|
||||||
Import sql
|
Import sql
|
||||||
|
|
||||||
inputfile tabel, Split colonner til {n}
|
inputfile tabel, Split colonner til {n}
|
||||||
sql :foo 'select * from bar' | parallel --colsep '\s+\|\s+' do_stuff {4} {1}
|
sql :foo 'select * from bar' | parallel --colsep '\|' do_stuff {4} {1}
|
||||||
|
|
||||||
|
|
||||||
parallel -a table_file --colsep '\s+' do_stuff {4} {1}
|
|
||||||
|
|
||||||
if(defined $::opt_colsep and defined @::opt_a and @::opt_a > 1) {
|
if(defined $::opt_colsep and defined @::opt_a and @::opt_a > 1) {
|
||||||
# must be done after converting :::: to -a -a
|
# must be done after converting :::: to -a -a
|
||||||
|
|
53
src/parallel
53
src/parallel
|
@ -1157,6 +1157,26 @@ B<ls *.es.* | perl -pe 'print; s/\.es//' | parallel -N2 cp {1} {2}>
|
||||||
The perl command spits out 2 lines for each input. GNU B<parallel>
|
The perl command spits out 2 lines for each input. GNU B<parallel>
|
||||||
takes 2 inputs (using B<-N2>) and replaces {1} and {2} with the inputs.
|
takes 2 inputs (using B<-N2>) and replaces {1} and {2} with the inputs.
|
||||||
|
|
||||||
|
=head1 EXAMPLE: Use a table as input
|
||||||
|
|
||||||
|
Content of table_file.tsv:
|
||||||
|
|
||||||
|
foo<TAB>bar
|
||||||
|
baz <TAB> quux
|
||||||
|
|
||||||
|
To run:
|
||||||
|
|
||||||
|
cmd -o bar -i foo
|
||||||
|
cmd -o quux -i baz
|
||||||
|
|
||||||
|
you can run:
|
||||||
|
|
||||||
|
parallel -a table_file.tsv --colsep '\t' cmd -o {2} -i {1}
|
||||||
|
|
||||||
|
Note: The default for GNU B<parallel> is to remove the spaces around the columns. To keep the spaces:
|
||||||
|
|
||||||
|
parallel -a table_file.tsv --trim n --colsep '\t' cmd -o {2} -i {1}
|
||||||
|
|
||||||
|
|
||||||
=head1 EXAMPLE: Working as cat | sh. Ressource inexpensive jobs and evaluation
|
=head1 EXAMPLE: Working as cat | sh. Ressource inexpensive jobs and evaluation
|
||||||
|
|
||||||
|
@ -2110,9 +2130,25 @@ sub read_args_from_command_line {
|
||||||
my $arg = shift @ARGV;
|
my $arg = shift @ARGV;
|
||||||
if($arg eq $Global::arg_sep) {
|
if($arg eq $Global::arg_sep) {
|
||||||
$Global::input_is_filename = (@new_argv);
|
$Global::input_is_filename = (@new_argv);
|
||||||
unget_argv(@ARGV);
|
while(@ARGV) {
|
||||||
$Global::total_jobs += @ARGV;
|
my $arg = shift @ARGV;
|
||||||
@ARGV=();
|
if($Global::end_of_file_string and
|
||||||
|
$arg eq $Global::end_of_file_string) {
|
||||||
|
# Ignore the rest of ARGV
|
||||||
|
@ARGV=();
|
||||||
|
}
|
||||||
|
if($Global::ignore_empty) {
|
||||||
|
if($arg =~ /^\s*$/) { next; }
|
||||||
|
}
|
||||||
|
if($Global::max_lines and $#ARGV >=0) {
|
||||||
|
if($arg =~ /\s$/) {
|
||||||
|
# Trailing space => continued on next line
|
||||||
|
$arg .= shift @ARGV;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unget_argv($arg);
|
||||||
|
$Global::total_jobs++;
|
||||||
|
}
|
||||||
last;
|
last;
|
||||||
} else {
|
} else {
|
||||||
push @new_argv, $arg;
|
push @new_argv, $arg;
|
||||||
|
@ -3477,7 +3513,9 @@ sub more_arguments {
|
||||||
# Returns:
|
# Returns:
|
||||||
# whether there are more arguments to be processed or not
|
# whether there are more arguments to be processed or not
|
||||||
my $fh = shift || $Global::argfile;
|
my $fh = shift || $Global::argfile;
|
||||||
return (@Global::unget_arg or @Global::unget_lines or not eof $fh);
|
return (@Global::unget_argv or @{$Global::unget_line{$fh}} or
|
||||||
|
@{$Global::unget_col{$fh}} or @Global::unget_arg or not
|
||||||
|
eof $fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_line_from_fh {
|
sub get_line_from_fh {
|
||||||
|
@ -3517,10 +3555,13 @@ sub get_line_from_fh {
|
||||||
return get_line_from_fh($fh);
|
return get_line_from_fh($fh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($Global::max_lines and not eof($fh)) {
|
if($Global::max_lines) {
|
||||||
if($arg =~ /\s$/) {
|
if($arg =~ /\s$/) {
|
||||||
# Trailing space => continued on next line
|
# Trailing space => continued on next line
|
||||||
$arg .= get_line_from_fh($fh);
|
my $cont = get_line_from_fh($fh);
|
||||||
|
if(defined $cont) {
|
||||||
|
$arg .= $cont;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug("get_line_from_fh ",$arg,"\n");
|
debug("get_line_from_fh ",$arg,"\n");
|
||||||
|
|
|
@ -9,6 +9,20 @@ echo '### Test of quoting of > bug if line continuation'
|
||||||
echo '### Test of --trim illegal'
|
echo '### Test of --trim illegal'
|
||||||
stdout parallel --trim fj ::: echo
|
stdout parallel --trim fj ::: echo
|
||||||
|
|
||||||
|
echo '### Test of eof string on :::'
|
||||||
|
parallel -E ole echo ::: foo ole bar
|
||||||
|
|
||||||
|
echo '### Test of ignore-empty string on :::'
|
||||||
|
parallel -r echo ::: foo '' ole bar
|
||||||
|
|
||||||
|
echo '### Test of trailing space continuation'
|
||||||
|
(echo foo; echo '';echo 'ole ';echo bar;echo quux) | xargs -r -L2 echo
|
||||||
|
(echo foo; echo '';echo 'ole ';echo bar;echo quux) | parallel -kr -L2 echo
|
||||||
|
parallel -kr -L2 echo ::: foo '' 'ole ' bar quux
|
||||||
|
(echo foo; echo '';echo 'ole ';echo bar;echo quux) | xargs -r -L2 -E bar echo
|
||||||
|
(echo foo; echo '';echo 'ole ';echo bar;echo quux) | parallel -kr -L2 -E bar echo
|
||||||
|
parallel -kr -L2 -E bar echo ::: foo '' 'ole ' bar quux
|
||||||
|
|
||||||
echo '### Test of --colsep'
|
echo '### Test of --colsep'
|
||||||
echo 'a%c%b' | parallel --colsep % echo {1} {3} {2}
|
echo 'a%c%b' | parallel --colsep % echo {1} {3} {2}
|
||||||
(echo 'a%c%b'; echo a%c%b%d) | parallel -k --colsep % echo {1} {3} {2} {4}
|
(echo 'a%c%b'; echo a%c%b%d) | parallel -k --colsep % echo {1} {3} {2} {4}
|
||||||
|
@ -19,6 +33,13 @@ parallel -k --colsep % echo {1} {3} {2} ::: a%c%b
|
||||||
|
|
||||||
parallel -k --colsep % echo {1} {3} {2} {4} ::: a%c%b a%c%b%d
|
parallel -k --colsep % echo {1} {3} {2} {4} ::: a%c%b a%c%b%d
|
||||||
|
|
||||||
|
echo '### Test of tab as colsep'
|
||||||
|
printf 'def\tabc\njkl\tghi' | parallel -k --colsep '\t' echo {2} {1}
|
||||||
|
parallel -k -a <(printf 'def\tabc\njkl\tghi') --colsep '\t' echo {2} {1}
|
||||||
|
|
||||||
|
echo '### Test of quoting after colsplit'
|
||||||
|
parallel --colsep % echo {2} {1} ::: '>/dev/null%>/tmp/null'
|
||||||
|
|
||||||
echo '### Test of --colsep as regexp'
|
echo '### Test of --colsep as regexp'
|
||||||
(echo 'a%c%%b'; echo a%c%b%d) | parallel -k --colsep %+ echo {1} {3} {2} {4}
|
(echo 'a%c%%b'; echo a%c%b%d) | parallel -k --colsep %+ echo {1} {3} {2} {4}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,24 @@
|
||||||
> > >
|
> > >
|
||||||
### Test of --trim illegal
|
### Test of --trim illegal
|
||||||
parallel: --trim must be one of: r l rl lr
|
parallel: --trim must be one of: r l rl lr
|
||||||
|
### Test of eof string on :::
|
||||||
|
foo
|
||||||
|
ole
|
||||||
|
### Test of ignore-empty string on :::
|
||||||
|
foo
|
||||||
|
ole
|
||||||
|
bar
|
||||||
|
### Test of trailing space continuation
|
||||||
|
foo ole bar
|
||||||
|
quux
|
||||||
|
foo ole bar
|
||||||
|
quux
|
||||||
|
foo ole bar
|
||||||
|
quux
|
||||||
|
foo ole
|
||||||
|
foo ole
|
||||||
|
foo ole bar
|
||||||
|
quux
|
||||||
### Test of --colsep
|
### Test of --colsep
|
||||||
a b c
|
a b c
|
||||||
a b c {4}
|
a b c {4}
|
||||||
|
@ -15,6 +33,13 @@ d e f
|
||||||
a b c
|
a b c
|
||||||
a b c {4}
|
a b c {4}
|
||||||
a b c d
|
a b c d
|
||||||
|
### Test of tab as colsep
|
||||||
|
abc def
|
||||||
|
ghi jkl
|
||||||
|
abc def
|
||||||
|
ghi jkl
|
||||||
|
### Test of quoting after colsplit
|
||||||
|
>/tmp/null >/dev/null
|
||||||
### Test of --colsep as regexp
|
### Test of --colsep as regexp
|
||||||
a b c {4}
|
a b c {4}
|
||||||
a b c d
|
a b c d
|
||||||
|
|
Loading…
Reference in a new issue