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

parallel: --plus {/%regexp/str} replace regexp$ with str.
This commit is contained in:
Ole Tange 2022-06-05 17:24:00 +02:00
parent f1b4a279a5
commit 5535b7cbeb
3 changed files with 24 additions and 2 deletions

View file

@ -2654,7 +2654,7 @@ sub check_invalid_option_combinations() {
sub init_globals() { sub init_globals() {
# Defaults: # Defaults:
$Global::version = 20220530; $Global::version = 20220605;
$Global::progname = 'parallel'; $Global::progname = 'parallel';
$::name = "GNU Parallel"; $::name = "GNU Parallel";
$Global::infinity = 2**31; $Global::infinity = 2**31;
@ -2731,7 +2731,11 @@ 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/%def/ghi} ${a/%def/}
'{/%([^}]+?)/([^}]*?)}' => 's/$$1$/$$2/g;',
# Bash ${a//def/ghi} ${a//def/} # Bash ${a//def/ghi} ${a//def/}
'{//([^}]+?)/([^}]*?)}' => 's/$$1/$$2/g;', '{//([^}]+?)/([^}]*?)}' => 's/$$1/$$2/g;',
# Bash ${a^a} # Bash ${a^a}

View file

@ -516,6 +516,16 @@ par_plus_dyn_repl() {
parallel --plus echo '{,,A}' ::: "$myvar" parallel --plus echo '{,,A}' ::: "$myvar"
parallel --plus echo '{2,,A}' ::: "wrong" ::: "$myvar" ::: "wrong" parallel --plus echo '{2,,A}' ::: "wrong" ::: "$myvar" ::: "wrong"
parallel --plus echo '{-2,,A}' ::: "wrong" ::: "$myvar" ::: "wrong" parallel --plus echo '{-2,,A}' ::: "wrong" ::: "$myvar" ::: "wrong"
myvar=abcabcdefdef
echo $myvar ${myvar/#abc/ABC}
echo $myvar | parallel --plus echo {} {/#abc/ABC}
echo $myvar ${myvar/%def/DEF}
echo $myvar | parallel --plus echo {} {/%def/DEF}
echo $myvar ${myvar/#abc/}
echo $myvar | parallel --plus echo {} {/#abc/}
echo $myvar ${myvar/%def/}
echo $myvar | parallel --plus echo {} {/%def/}
} }
par_keeporder_roundrobin() { par_keeporder_roundrobin() {

View file

@ -1668,6 +1668,14 @@ 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 abcabcdefdef ABCabcdefdef
par_plus_dyn_repl abcabcdefdef ABCabcdefdef
par_plus_dyn_repl abcabcdefdef abcabcdefDEF
par_plus_dyn_repl abcabcdefdef abcabcdefDEF
par_plus_dyn_repl abcabcdefdef abcdefdef
par_plus_dyn_repl abcabcdefdef abcdefdef
par_plus_dyn_repl abcabcdefdef abcabcdef
par_plus_dyn_repl abcabcdefdef abcabcdef
par_race_condition1 ### Test race condition on 8 CPU (my laptop) par_race_condition1 ### Test race condition on 8 CPU (my laptop)
par_race_condition1 1 par_race_condition1 1
par_race_condition1 2 par_race_condition1 2