sed提取模式内容

小磊z

关注

阅读 45

2023-06-15


提取模式开始和结束之间的部分:

sed 's/.*BEGIN_TEXT\(.*\)END_TEXT.*/\1/g' log.txt | sort  | uniq

例如提取下面的数字2:

tom says: I have 2 books on the table
 lily says: I have 3 books on the table

sed 's/.*I have \(.*\) books on.*/\1/g' log.txt

输出:

2
3

参考:
http://coolshell.cn/articles/9070.html
http://coolshell.cn/articles/9104.html



精彩评论(0)

0 0 举报