[SOLVED] How to remove extra symbols before and after named argument in Batch Script?

AlvinSeville

Prominent
Sep 7, 2020
13
0
520
gitlab.com
Hello! My task is to remove all extra symbols from named argument. For instance I have ,,,--no-color,, option passed to script and I have to cut everything but --no-color. I've solved it via Bash code:
Bash:
shopt -s extglob
option="--no-color,,"
pattern="--+([[:alpha:]]*(-[[:alpha:]]))"

while [[ "$option" == @(+(,)$pattern|$pattern+(,)|+(,)$pattern+(,)) ]]
do
  option=${option##*(,)}
  option=${option%%*(,)}
done

echo "$option"
(you can also open it via Repl.it)
And now I wanna translate it to Batch Script. How can I do it? I don't know how to rewrite this globbing expression to batch file @(+(,)$pattern|$pattern+(,)|+(,)$pattern+(,)).
 
Solution
I've found the solution - use sed command:

Code:
@echo off
sed -i -e "s/^,*//g" -e "s/,$*//g" test.txt
pause
or:
Code:
@echo off
sed -i "s/,//g" test.txt
pause

Ralston18

Titan
Moderator
Have noted your other similar posts regarding Bash and Batch....

My suggestion is to make an attempt to write the required Batch Scrip relevant to the requirement to remove extra spaces. Document your script (line by line if necessary) to explain your work/script.

Test script showing inputs and outputs.

Post.

Explain the fixes that you have tried and what worked and what did not work.