Sorry if this has been asked before, but I haven't found anything so far.
Here's the thing: I have a string and a pattern, and want to surround the pattern inside the string with brackets.
While I want to surround the pattern regardless if it has been matched case-sensitively or not, I want to have it in the same case as it was in the original string.
Here's my best try so far:
#!/bin/bash STRING="ABCBD" PATTERN="b" echo $STRING | sed "s/$PATTERN/[$PATTERN]/Ig"
The output for this is
A[b]C[b]D. However, I would like it to be
If the pattern was
B instead of
b, the output should also be
If the string was
abcbd instead of
ABCBD, the output should be
a[b]c[b]d for both patterns
Do you know any tricks to achieve this? I am glad for any help.