parallel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: {n#} and {n##} Positional replacement​ with job number and total job


From: Ole Tange
Subject: Re: {n#} and {n##} Positional replacement​ with job number and total jobs
Date: Sun, 9 Oct 2016 17:30:28 +0200

On Sat, Oct 8, 2016 at 1:41 PM, Wei Li <wei2@kth.se> wrote:

> how to implement  Positional replacement with job number and total jobs?
>
> {n#} and {n##}
>
> like {#} and {##} but only for position "n"

I imagine you want this output:

$ parallel echo {1#} of {1##} and {2#} of {2##} ::: A B ::: C D E
1 of 2 and 1 of 3
1 of 2 and 2 of 3
1 of 2 and 3 of 3
2 of 2 and 1 of 3
2 of 2 and 2 of 3
2 of 2 and 3 of 3

It is not trivially simple to do. The total can be done like this:

    --rpl '{#tot}
total_jobs();$_=1+$#{$job->{arg_queue}->{arg_sub_queue}->{arg_matrix}->[$1-1]}'

E.g:

    parallel --rpl '{#tot}
total_jobs();$_=1+$#{$job->{arg_queue}->{arg_sub_queue}->{arg_matrix}->[$1-1]}'
echo {1} of {1#tot} and {2} of {2#tot} ::: A B ::: C D E

But GNU Parallel does not know the current index in the input source.
There is no [$i,$j] counter associated with each job.

This is due to GNU Parallel not generating the full arg_matrix before
starting jobs. arg_matrix is generated as it is needed. The reason for
this is to be able to do:

    cat | parallel echo :::: - ::: 1 2 3

Here jobs will start running even before we know how many {1} there will be.


/Ole



reply via email to

[Prev in Thread] Current Thread [Next in Thread]