How can I take a string like this:
sample="+TEST/TEST01/filetest01.txt"
And replace all occurrences of test01/TEST01 with test02/TEST02, keeping the text in the same case. So the desired output would be:
"+TEST/TEST02/filetest02.txt"
If you were to pass the replacement string of TEST03. Then the desired output would be
"+TEST/TEST03/filetest03.txt"
If the replacement text was Test04. The desired output:
"+TEST/TEST04/filetest04.txt"
I've tried this:
echo "$sample" | awk 'BEGIN{IGNORECASE=1}{gsub("test01", "test02");print}'
It replaces the lower case value but not the upper case.
I cannot use sed as the version I have doesn't support the /I switch to ignore case.
My end goal is to be able to use variables that represent the Item to change. So variables would be like this:
text2replace=test01
replacetext=test02