[英]Use sed or grep to get number and . only from a string
我尝试sed -r '/[^0-9.,]+/'
, sed -r '/[^0-9.,]+/'
和grep -oE '/[^0-9.,]+/'
, grep -oE '/[^0-9.,]+/'
为(123.123.123.123)
,它返回bad pattern
If you only want numbers and dot you must remove the ^
in first position inside []
because it means the contrary "all except". 如果只需要数字和点,则必须删除
[]
内第一位置的^
,因为这意味着相反的“所有除外”。
Also forward slashes must be suppressed in grep expression argument. 同样,必须在grep表达式参数中禁止使用正斜杠。
grep -oE '[0-9.,]+'
Just use tr
command to delete the parentheses instead of trying to use a regex with grep
or sed
只需使用
tr
命令删除括号即可,而不是尝试在grep
或sed
使用正则表达式
echo "(123.123.123.123)" | tr -d '()'
123.123.123.123
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.