[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Replacement strings
From: |
Cook, Malcolm |
Subject: |
RE: Replacement strings |
Date: |
Wed, 25 Jun 2014 17:17:38 +0000 |
Ole!
I would like to see something like this in parallel.
I don't think fex provides a good model for the syntax.
Given that your implementation is in Perl, you might consider extending the
syntax to allow
any Perl expression can appear between the braces
the expression is evaluated in the context where $_ is bound to the
(chomped) current line of input.
the value of the bracketed expression is the value of $_ after
evaluating the expression.
Then you could write, for example:
example current syntax meaning / note
{$_} {} the current line
{s/\.[^.]+$//} {.} the current line after
trimming an extension (but, dangerous, as written would trim from first '.'
even if part of dirname)
{qx|basename $_|} {/} basename - directory
removed - uses perl qx operator to call out to system
{qx|dirname $_|} {/} directory name
Removal of multiple extensions is now a matter or writing the regex:
{s/(\.[^.]+$){2}//} {.} the current
line after trimming exactly two extensions
{s/(\.[^.]+$){,2}//} {.} the current
line after trimming up to two extensions
Other possibilities immediately come to mind
find . -name '*.tif' | parallel mv {} '{s/(\d+)/sprintf("%07s",$1)/}' #
rename all tif files so numeric stem is zero padded in a field of 7 zeros
find images -type d | parallel -j1 mkdir -p {/^images/cropped.images/}
# create 'cropped.images' directory structure parallel to 'images' nb -j1 is
required to avoid contention
find images -name '*.tif' | parallel crop {} {/^images/cropped.images/}
# `crop` all tifs in thisdir into a parallel directory structure
Also, handling of --header options such as your examples with $gender and
$size, could also allow recodings, such as:
{switch($gender) { switch case "m" "male" case "f" "female"
I think this might sit VERY NICELY with your implementation, and provide LOTS
of new USEFUL and SUCCINT idiomatic uses of parallel.
On the topic, both bash and gnu make provide syntax for parameter expansion
which might fruitfully be co-opted to your purpose. But I like using the perl
model.
Cheers,
Malcolm
>-----Original Message-----
>From: parallel-bounces+mec=stowers.org@gnu.org
>[mailto:parallel-bounces+mec=stowers.org@gnu.org] On Behalf Of Ole Tange
>Sent: Tuesday, June 03, 2014 4:56 PM
>To: parallel@gnu.org
>Subject: Replacement strings
>
>Currently GNU Parallel has 6 replacement strings:
>
>{} = A/B/C.D.E
>{.} = A/B/C.D
>{#} = Job number
>{%} = Job slot
>{//} = A/B
>{/} = C.D.E
>{/.} = C.D
>
>(Plus the numbered {1} and {-1}).
>
>But there has been a demand for removing two extensions and a
>replacement string for the removed extension. If these should be
>implemented, I would like to have a more general syntax. It could be
>something like:
>
>{+.} = E
>{+/} = A/B
>{..} = A/B/C
>{+..} = D.E
>
>{} = {.}.{+.} = {+/}/{/} = {+/}/{/.}.{+.} = {..}.{+..}
>
>The idea is here that '+' matches the opposite of the non-+ version
>(except for the . or / separating). {//} would be the only redundant
>string (in the new syntax that is {+/}).
>
>If it is easy to implement then {...} {/..} {/...} and the +-versions
>should work, too.
>
>There would still no replacement string for 'A', 'B' or 'D'.
>
>Better ideas for syntax? Is there any good existing syntax for
>replacements that would make sense? E.g. FEX
>http://www.semicomplete.com/projects/fex/
>
>
>/Ole
- Replacement strings, Ole Tange, 2014/06/03
- RE: Replacement strings,
Cook, Malcolm <=
- Message not available