[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Replacement strings
From: |
Ole Tange |
Subject: |
Re: Replacement strings |
Date: |
Thu, 26 Jun 2014 02:20:06 +0200 |
On Wed, Jun 25, 2014 at 11:53 PM, Ole Tange <ole@tange.dk> wrote:
> So instead it could be {{perl expression}}. I don't think the {{...}}
> is something you would otherwise write on the command line.
The very basic functionality now works:
# {}
parallel echo '{{}}' ::: 1/2.3.4.5 3/4.6.7.8
# {/}
parallel echo '{{s:.*/::}}' ::: ab.bc/cd.de
# {//}
parallel echo '{{s:/[^/]+$::}}' ::: i/ab.bc/cd.de
# {/.}
parallel echo '{{s:.*/([^/]+)\.[^/.]+$:$1:}}' ::: i/ab.bc/cd.de
# {.}
parallel echo '{{s:\.[^/.]+$::}}' ::: i/ab.bc/cd.de
parallel echo '{{s/\.[^.]+$//}}' ::: 1/2.3.4.5 3/4.6.7.8
parallel echo '{{$_=qx|basename $_|}}' ::: 1/2.3.4.5 3/4.6.7.8
parallel echo '{{$_=qx|dirname $_|}}' ::: 1/2.3.4.5 3/4.6.7.8
parallel echo '{{s/(\.[^.]+){2}$//}}' ::: 1/2.3.4.5 3/4.6.7.8
parallel echo '{{s/(\.[^.]+){0,2}$//}}' ::: 1/2.3.4.5 3/4.6.7.8
parallel echo '{{$_=$_+1}}' ::: 1 2 3
For positional arguments @_ is initialised with all the positional
arguments, so $_[0] == {1}, but I am not sure how that can be useful
as the {{perl expr}} is evaluated for each argument:
parallel -n3 echo '{{$_=$_[0]}}' ::: 1 2 3 4
1 1 1
4
I had to choose whether the expression is the return value or whether
the return value is in $_. I have chosen the latter as that is how
rename(1) also works. That means this does NOT work (because it does
NOT set $_):
parallel echo '{{qx|basename $_|}}' ::: 1/2.3.4.5 3/4.6.7.8
parallel echo '{{qx|dirname $_|}}' ::: 1/2.3.4.5 3/4.6.7.8
parallel echo '{{$_+1}}' ::: 1 2 3
Alternatively the s/// should return $_ like this:
parallel echo '{{s/\.[^.]+$//; $_}}' ::: 1/2.3.4.5 3/4.6.7.8
It is easy to change the behaviour (line 6191), so maybe we will just
see which one is better.
The prototype does not work very well with -m/-n and it does not work
at all with -X/-N, and while it is clear to me that it should work
similar to {} for multiple arguments (append with space or with
context and space), I do not see how a similar positional argument can
be made (and maybe we do not care):
parallel -n4 echo {1} {{do only this for arg 2}} {-1} ::: a b c d
How can I see that the {{..}} is only for arg 2?
/Ole