How can I remove everything after a whitespace? I can do it if I specify the colon ':' rather than [[:space:]].
$ cat t.sh
echo "DW_Prod\\Facets\\UNRCH_MBRS: UNRCH_Members.sql" | \
sed -r -e 's#.*\(DW_Prod.*\)[[:space:]].*#\\1#'
$ ./t.sh
DW_Prod\Facets\UNRCH_MBRS: UNRCH_Members.sql
You are enabling ERE metachars with -r and then disabling the ERE capture groups (...) by escaping the delimiters \(...\) and disabling the backreference \1 by escaping the backslash \\1. Try this:
$ echo "DW_Prod\\Facets\\UNRCH_MBRS: UNRCH_Members.sql" | \
sed -r -e 's#.*(DW_Prod.*)[[:space:]].*#\1#'
DW_Prod\Facets\UNRCH_MBRS:
All you really need though is:
$ echo "DW_Prod\\Facets\\UNRCH_MBRS: UNRCH_Members.sql" |
sed 's#[[:space:]].*##'
DW_Prod\Facets\UNRCH_MBRS:
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