sed如何实现grep -o的功能.

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/30 01:09:46
sed如何实现grep -o的功能.

sed如何实现grep -o的功能.
sed如何实现grep -o的功能.

sed如何实现grep -o的功能.
grep 的 -o 选项:
-o, --only-matching
Show only the part of a matching line that matches PATTERN.

$ echo "hello" | grep -o "he"
he

sed利用正则表达式和group功能同样可以实现:
$ echo "hello" | sed -n 's/.*\(he\).*/\1/;p'
he