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}
'{%%([^}]+?)}' => 's/$$1$//;',
# 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}
'{^([^}]+?)}' => 's/^($$1)/uc($1)/e;',
# Bash ${a^^a}

View file

@ -1953,7 +1953,8 @@ inspired by bash's parameter expansion:
{##regexp} remove prefix regexp (greedy)
{%regexp} remove postfix regexp (non-greedy)
{%%regexp} remove postfix regexp (greedy)
{/regexp/str} replace regexp with str
{/regexp/str} replace one regexp with str
{//regexp/str} replace every regexp with str
{^str} uppercase str if found at the start
{^^str} uppercase str
{,str} lowercase str if found at the start

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"
myvar=abcAaAdef
myvar=abcAaBdefCdefDdef
echo ${myvar:2}
parallel --rpl '{:(\d+)} substr($_,0,$$1) = ""' 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"
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}
parallel --rpl '{^(.+?)} s/^($$1)/uc($1)/e;' 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 cAaAdef
par_plus_dyn_repl cAaAdef
par_plus_dyn_repl cAaAdef
par_plus_dyn_repl cAaAdef
par_plus_dyn_repl cAaAdef
par_plus_dyn_repl cAaBdefCdefDdef
par_plus_dyn_repl cAaBdefCdefDdef
par_plus_dyn_repl cAaBdefCdefDdef
par_plus_dyn_repl cAaBdefCdefDdef
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 9
par_plus_dyn_repl 9
par_plus_dyn_repl 17
par_plus_dyn_repl 17
par_plus_dyn_repl 1
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 AaAdef
par_plus_dyn_repl AaAdef
par_plus_dyn_repl AaAdef
par_plus_dyn_repl AaAdef
par_plus_dyn_repl AaAdef
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 abcAaA
par_plus_dyn_repl abcAaA
par_plus_dyn_repl abcAaA
par_plus_dyn_repl abcAaA
par_plus_dyn_repl abcAaA
par_plus_dyn_repl abcAaAghi
par_plus_dyn_repl abcAaAghi
par_plus_dyn_repl abcAaAghi
par_plus_dyn_repl abcAaAghi
par_plus_dyn_repl abcAaAghi
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
par_plus_dyn_repl AbcAAAdef
par_plus_dyn_repl AbcAAAdef
par_plus_dyn_repl AbcAAAdef
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 AaBdefCdefDdef
par_plus_dyn_repl AaBdefCdefDdef
par_plus_dyn_repl AaBdefCdefDdef
par_plus_dyn_repl AaBdefCdefDdef
par_plus_dyn_repl AaBdefCdefDdef
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 abcAaBdefCdefD
par_plus_dyn_repl abcAaBdefCdefD
par_plus_dyn_repl abcAaBdefCdefD
par_plus_dyn_repl abcAaBdefCdefD
par_plus_dyn_repl abcAaBdefCdefD
par_plus_dyn_repl abcAaBghiCdefDdef
par_plus_dyn_repl abcAaBghiCdefDdef
par_plus_dyn_repl abcAaBghiCdefDdef
par_plus_dyn_repl abcAaBghiCdefDdef
par_plus_dyn_repl abcAaBghiCdefDdef
par_plus_dyn_repl abcAaBghiCghiDghi
par_plus_dyn_repl abcAaBghiCghiDghi
par_plus_dyn_repl abcAaBghiCghiDghi
par_plus_dyn_repl abcAaBghiCghiDghi
par_plus_dyn_repl abcAaBghiCghiDghi
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 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