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

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