使用 sed 将一行中的特定部分切出来. extract substring by pattern. regex
cat xxxxx |grep xxxx | sed -n 's/REGEX_FULLLINE/\1/p'
例:
echo "regular expression - extract part of string using sed" |sed -n 's/.*- extract \(.*\) using.*/\1/p'
在 regular expression - extract part of string using sed
中截取 - extract 和 using 中间的部分
-n
表示关闭 sed 的自动打印 pattern space 的功能
最后的 p
表示对于执行了替换的行进行打印.
注意 sed 中正则表达式需完全匹配整行内容, 因此首尾的 .*
用来使 sed 能够正确匹配到目标行, 不能省略!