I need to strip an underscore optionally if it exists.
string VIEW VXABC expected result VIEW ABC
string VIEW V_XABC expected result VIEW ABC
This is my try but results are eluding me
echo "VIEW VXABC" |sed 's/VIEW V_?X/VIEW ABC/'
VIEW VXABC
[me@home]$ echo VIEW V_XABC | sed -r 's/VIEW V_?X/VIEW /'
VIEW ABC
[me@home]$ echo VIEW VXABC | sed -r 's/VIEW V_?X/VIEW /'
VIEW ABC
Note the -r option. From the man page:
-r, --regexp-extended
use extended regular expressions in the script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With