Issue
How to do replacement using sed
or perl
with multiple input strings and one string is substring of other string.
Example:
Input : a[b][c]
Expected Output: a.*b.*c.*
I tried following but the ][
between b and c is messing up the results.
echo "a[b][c]" |sed -r 's/[\[\]]{1}|\[|\]/.*/g'
a.*b.*.*c.*
echo "a[b][c]" |sed -r 's/[\[\]]|\[|\]/.*/g'
a.*b.*.*c.*
I was hoping is someone could help, Thanks. preferring perl
solution as I have to fit this into rest of the unshared code.
Solution
echo "a[b][c]" | sed 's/]/.*/g; s/\[/.*/; s/\[//g'
Output:
a.*b.*c.*
Or replace sed
with perl -pe
.
Answered By - Cyrus