-2
I’m trying to create a script to automate a job I do. Everything was going well until I found this problem. When I use the sed
, to remove a word from the string, the output shows 2 commas together, and this can cause faults in the edited parameter. Ex: Removing "BBB"
Domain.vmfull="AAAAA,BBBBB,CCCCC,ABCDE"
Domain.vmfull="AAAAA,,CCCCC,ABCDE"
Question 1 How can I remove one of these 2 commas? The output should look like this:
Domain.vmfull="AAAAA,CCCCC,ABCDE"
Question 2 Otherwise, when the word to be removed is the last or the first on the list, the unnecessary comma will be the first or the last. How can I avoid both possibilities? Ex: as below by removing AAAAA:
Domain.vmfull=",BBBBB,CCCCC,ABCDE"
the exit must be:
Domain.vmfull="BBBBB,CCCCC,ABCDE"
bash-3.2$ echo "$options_sched"
"-vmfulltype=vstor -vmbackuptype=fullvm -asnodename=NODE1 -MODE=IFIncremental -domain.vmfull="AAAAA,BBBBB,CCCCC,ABCDE""
bash-3.2$ options_final=$(echo $options_sched | sed "s#BBBBB##gI")
bash-3.2$ echo $options_final
"-vmfulltype=vstor -vmbackuptype=fullvm -asnodename=NODE1 -MODE=IFIncremental -domain.vmfull="AAAAA,,CCCCC,ABCDE""
#Question - 2
bash-3.2$ echo "$options_sched"
"-vmfulltype=vstor -vmbackuptype=fullvm -asnodename=NODE1 -MODE=IFIncremental -domain.vmfull="AAAAA,BBBBB,CCCCC,ABCDE""
bash-3.2$ options_final=$(echo $options_sched | sed "s#AAAAA##gI")
bash-3.2$ echo $options_final
"-vmfulltype=vstor -vmbackuptype=fullvm -asnodename=NODE1 -MODE=IFIncremental -domain.vmfull=",BBBBB,CCCCC,ABCDE""