parallel: --plus {//regexp/str} replace every regexp with str.

This commit is contained in:
Ole Tange 2022-05-27 20:54:35 +02:00
parent d2753adec5
commit 2f85da8167
4 changed files with 75 additions and 61 deletions

View file

@ -2731,7 +2731,9 @@ sub init_globals() {
# Bash ${a%%def} # Bash ${a%%def}
'{%%([^}]+?)}' => 's/$$1$//;', '{%%([^}]+?)}' => 's/$$1$//;',
# Bash ${a/def/ghi} ${a/def/} # Bash ${a/def/ghi} ${a/def/}
'{/([^}]+?)/([^}]*?)}' => 's/$$1/$$2/;', '{/([^}/]+?)/([^}]*?)}' => 's/$$1/$$2/;',
# Bash ${a//def/ghi} ${a//def/}
'{//([^}]+?)/([^}]*?)}' => 's/$$1/$$2/g;',
# Bash ${a^a} # Bash ${a^a}
'{^([^}]+?)}' => 's/^($$1)/uc($1)/e;', '{^([^}]+?)}' => 's/^($$1)/uc($1)/e;',
# Bash ${a^^a} # Bash ${a^^a}

View file

@ -1937,27 +1937,28 @@ B<{uniq}> skips jobs where values from two input sources are the same.
Shorthands for variables: Shorthands for variables:
{slot} $PARALLEL_JOBSLOT (see {%}) {slot} $PARALLEL_JOBSLOT (see {%})
{sshlogin} $PARALLEL_SSHLOGIN {sshlogin} $PARALLEL_SSHLOGIN
{host} $PARALLEL_SSHHOST {host} $PARALLEL_SSHHOST
{agrp} $PARALLEL_ARGHOSTGROUPS {agrp} $PARALLEL_ARGHOSTGROUPS
{hgrp} $PARALLEL_HOSTGROUPS {hgrp} $PARALLEL_HOSTGROUPS
The following dynamic replacement strings are also activated. They are The following dynamic replacement strings are also activated. They are
inspired by bash's parameter expansion: inspired by bash's parameter expansion:
{:-str} str if the value is empty {:-str} str if the value is empty
{:num} remove the first num characters {:num} remove the first num characters
{:pos:len} substring from position pos length len {:pos:len} substring from position pos length len
{#regexp} remove prefix regexp (non-greedy) {#regexp} remove prefix regexp (non-greedy)
{##regexp} remove prefix regexp (greedy) {##regexp} remove prefix regexp (greedy)
{%regexp} remove postfix regexp (non-greedy) {%regexp} remove postfix regexp (non-greedy)
{%%regexp} remove postfix regexp (greedy) {%%regexp} remove postfix regexp (greedy)
{/regexp/str} replace regexp with str {/regexp/str} replace one regexp with str
{^str} uppercase str if found at the start {//regexp/str} replace every regexp with str
{^^str} uppercase str {^str} uppercase str if found at the start
{,str} lowercase str if found at the start {^^str} uppercase str
{,,str} lowercase str {,str} lowercase str if found at the start
{,,str} lowercase str
See also: B<--rpl> B<{}> See also: B<--rpl> B<{}>

View file

@ -442,7 +442,7 @@ par_plus_dyn_repl() {
parallel --plus echo {2:-myval} ::: "wrong" ::: "$myvar" ::: "wrong" parallel --plus echo {2:-myval} ::: "wrong" ::: "$myvar" ::: "wrong"
parallel --plus echo {-2:-myval} ::: "wrong" ::: "$myvar" ::: "wrong" parallel --plus echo {-2:-myval} ::: "wrong" ::: "$myvar" ::: "wrong"
myvar=abcAaAdef myvar=abcAaBdefCdefDdef
echo ${myvar:2} echo ${myvar:2}
parallel --rpl '{:(\d+)} substr($_,0,$$1) = ""' echo {:2} ::: "$myvar" parallel --rpl '{:(\d+)} substr($_,0,$$1) = ""' echo {:2} ::: "$myvar"
parallel --plus echo {:2} ::: "$myvar" parallel --plus echo {:2} ::: "$myvar"
@ -488,6 +488,12 @@ par_plus_dyn_repl() {
parallel --plus echo {2/def/ghi} ::: "wrong" ::: "$myvar" ::: "wrong" parallel --plus echo {2/def/ghi} ::: "wrong" ::: "$myvar" ::: "wrong"
parallel --plus echo {-2/def/ghi} ::: "wrong" ::: "$myvar" ::: "wrong" parallel --plus echo {-2/def/ghi} ::: "wrong" ::: "$myvar" ::: "wrong"
echo ${myvar//def/ghi}
parallel --rpl '{//(.+?)/(.+?)} s/$$1/$$2/g;' echo {//def/ghi} ::: "$myvar"
parallel --plus echo {//def/ghi} ::: "$myvar"
parallel --plus echo {2//def/ghi} ::: "wrong" ::: "$myvar" ::: "wrong"
parallel --plus echo {-2//def/ghi} ::: "wrong" ::: "$myvar" ::: "wrong"
echo ${myvar^a} echo ${myvar^a}
parallel --rpl '{^(.+?)} s/^($$1)/uc($1)/e;' echo {^a} ::: "$myvar" parallel --rpl '{^(.+?)} s/^($$1)/uc($1)/e;' echo {^a} ::: "$myvar"
parallel --plus echo {^a} ::: "$myvar" parallel --plus echo {^a} ::: "$myvar"

View file

@ -1605,54 +1605,59 @@ par_plus_dyn_repl myval
par_plus_dyn_repl myval par_plus_dyn_repl myval
par_plus_dyn_repl myval par_plus_dyn_repl myval
par_plus_dyn_repl myval par_plus_dyn_repl myval
par_plus_dyn_repl cAaAdef par_plus_dyn_repl cAaBdefCdefDdef
par_plus_dyn_repl cAaAdef par_plus_dyn_repl cAaBdefCdefDdef
par_plus_dyn_repl cAaAdef par_plus_dyn_repl cAaBdefCdefDdef
par_plus_dyn_repl cAaAdef par_plus_dyn_repl cAaBdefCdefDdef
par_plus_dyn_repl cAaAdef par_plus_dyn_repl cAaBdefCdefDdef
par_plus_dyn_repl cAa par_plus_dyn_repl cAa
par_plus_dyn_repl cAa par_plus_dyn_repl cAa
par_plus_dyn_repl cAa par_plus_dyn_repl cAa
par_plus_dyn_repl cAa par_plus_dyn_repl cAa
par_plus_dyn_repl cAa par_plus_dyn_repl cAa
par_plus_dyn_repl 9 par_plus_dyn_repl 17
par_plus_dyn_repl 9 par_plus_dyn_repl 17
par_plus_dyn_repl 1 par_plus_dyn_repl 1
par_plus_dyn_repl abcAaAdef par_plus_dyn_repl abcAaBdefCdefDdef
par_plus_dyn_repl abcAaAdef par_plus_dyn_repl abcAaBdefCdefDdef
par_plus_dyn_repl abcAaAdef par_plus_dyn_repl abcAaBdefCdefDdef
par_plus_dyn_repl abcAaAdef par_plus_dyn_repl abcAaBdefCdefDdef
par_plus_dyn_repl abcAaAdef par_plus_dyn_repl abcAaBdefCdefDdef
par_plus_dyn_repl AaAdef par_plus_dyn_repl AaBdefCdefDdef
par_plus_dyn_repl AaAdef par_plus_dyn_repl AaBdefCdefDdef
par_plus_dyn_repl AaAdef par_plus_dyn_repl AaBdefCdefDdef
par_plus_dyn_repl AaAdef par_plus_dyn_repl AaBdefCdefDdef
par_plus_dyn_repl AaAdef par_plus_dyn_repl AaBdefCdefDdef
par_plus_dyn_repl abcAaAdef par_plus_dyn_repl abcAaBdefCdefDdef
par_plus_dyn_repl abcAaAdef par_plus_dyn_repl abcAaBdefCdefDdef
par_plus_dyn_repl abcAaAdef par_plus_dyn_repl abcAaBdefCdefDdef
par_plus_dyn_repl abcAaAdef par_plus_dyn_repl abcAaBdefCdefDdef
par_plus_dyn_repl abcAaAdef par_plus_dyn_repl abcAaBdefCdefDdef
par_plus_dyn_repl abcAaA par_plus_dyn_repl abcAaBdefCdefD
par_plus_dyn_repl abcAaA par_plus_dyn_repl abcAaBdefCdefD
par_plus_dyn_repl abcAaA par_plus_dyn_repl abcAaBdefCdefD
par_plus_dyn_repl abcAaA par_plus_dyn_repl abcAaBdefCdefD
par_plus_dyn_repl abcAaA par_plus_dyn_repl abcAaBdefCdefD
par_plus_dyn_repl abcAaAghi par_plus_dyn_repl abcAaBghiCdefDdef
par_plus_dyn_repl abcAaAghi par_plus_dyn_repl abcAaBghiCdefDdef
par_plus_dyn_repl abcAaAghi par_plus_dyn_repl abcAaBghiCdefDdef
par_plus_dyn_repl abcAaAghi par_plus_dyn_repl abcAaBghiCdefDdef
par_plus_dyn_repl abcAaAghi par_plus_dyn_repl abcAaBghiCdefDdef
par_plus_dyn_repl AbcAaAdef par_plus_dyn_repl abcAaBghiCghiDghi
par_plus_dyn_repl AbcAaAdef par_plus_dyn_repl abcAaBghiCghiDghi
par_plus_dyn_repl AbcAaAdef par_plus_dyn_repl abcAaBghiCghiDghi
par_plus_dyn_repl AbcAaAdef par_plus_dyn_repl abcAaBghiCghiDghi
par_plus_dyn_repl AbcAaAdef par_plus_dyn_repl abcAaBghiCghiDghi
par_plus_dyn_repl AbcAAAdef par_plus_dyn_repl AbcAaBdefCdefDdef
par_plus_dyn_repl AbcAAAdef par_plus_dyn_repl AbcAaBdefCdefDdef
par_plus_dyn_repl AbcAAAdef par_plus_dyn_repl AbcAaBdefCdefDdef
par_plus_dyn_repl AbcAAAdef par_plus_dyn_repl AbcAaBdefCdefDdef
par_plus_dyn_repl AbcAAAdef par_plus_dyn_repl AbcAaBdefCdefDdef
par_plus_dyn_repl AbcAABdefCdefDdef
par_plus_dyn_repl AbcAABdefCdefDdef
par_plus_dyn_repl AbcAABdefCdefDdef
par_plus_dyn_repl AbcAABdefCdefDdef
par_plus_dyn_repl AbcAABdefCdefDdef
par_plus_dyn_repl abcAaAdef par_plus_dyn_repl abcAaAdef
par_plus_dyn_repl abcAaAdef par_plus_dyn_repl abcAaAdef
par_plus_dyn_repl abcAaAdef par_plus_dyn_repl abcAaAdef