In case you are doing some form of build configuration through make, you can use gmtt which is a library with functionality supporting this task. In gmtt you can formulate your task like this:
include gmtt/gmtt.mk
cfg-table := 2 $(cfg) # make a gmtt-table from the variable
# now select column 1 and 2 from the table for the right test and format the output (without the need to format, just use "select")
smoketest-cfg := $(call map-select,1 2,$(cfg-table),$$(call glob-match,$$1,smoketest*),+uvm_set_config=*$(comma)$$1$(comma)$$2)
regressiontest-cfg := $(call map-select,1 2,$(cfg-table),$$(call glob-match,$$1,regressiontest*),+uvm_set_config=*$(comma)$$1$(comma)$$2)
$(info $(smoketest-cfg))
$(info $(regressiontest-cfg))
$(info -----------------------)
$(info $(subst $(space),$(newline),$(strip $(smoketest-cfg))))
and you should now be able to call it like:
make cfg="smoketest-A 1 smoketest-B 2 regressiontest-A 3 regressiontest-B 4"
(gmtt uses tables which are just GNUmake lists, therefore you must use spaces as separators of the items and you must not have empty "cells".)
Output:
+uvm_set_config=*,smoketest-A,1 +uvm_set_config=*,smoketest-B,2
+uvm_set_config=*,regressiontest-A,3 +uvm_set_config=*,regressiontest-B,4
-----------------------
+uvm_set_config=*,smoketest-A,1
+uvm_set_config=*,smoketest-B,2
Note that you need to quote ,
in your output format as $(comma)
(a variable provided by gmtt) because of the generous character handling of make which takes nearly everything as a function parameter, even \
, which therefore doesn't help as escaping character.