I am trying to validate some inputs to remove a set of characters. Only alphanumeric characters plus, period, underscore, hyphen are allowed. I've tested the regex expression [^w.-] here http://gskinner.com/RegExr/ and it matches what I want removed so I not sure why sed is returning the opposite. What am I missing?
[^w.-]
sed
My end goal is to input "?10.41.89.50 " and get "10.41.89.50".
"?10.41.89.50 "
"10.41.89.50
I've tried:
echo "?10.41.89.50 " | sed s/[^w.-]//g returns ?...
echo "?10.41.89.50 " | sed s/[^w.-]//g
?...
echo "?10.41.89.50 " | sed s/[w.-]//g and echo "?10.41.89.50 " | sed s/[w^.-]//g returns ?10418950
echo "?10.41.89.50 " | sed s/[w.-]//g
echo "?10.41.89.50 " | sed s/[w^.-]//g
?10418950
I attempted the answer found here Skip/remove non-ascii character with sed but nothing was removed.
tr's -c (complement) flag may be an option
-c
echo "?10.41.89.50-._ " | tr -cd '[:alnum:]._-'
2.1m questions
2.1m answers
60 comments
57.0k users