2014-10-28 28 views
0

之间的连接状态我以前grep命令file.xml <cite> </cite>之间解压的一切:使用bash到标签

grep -Po "(?<=<cite>).*?(?=</cite>)" /tmp/file.xml 

的结果是这样的:

<strong>site.com</strong>/<strong>blahblah</strong>/foo #and may be with more tags named strong 
<strong>site2.com</strong>/req/?<strong>blahblah2</strong>=foo 

现在我想有结果是这样的:

site.com/blahblah/foo 
site2.com/req/?blahblah2=foo 

我想删除添加<strong></strong>并附加其他...

如果在蟒蛇这也欢迎大家使用xpath的方式...

回答

2

使用SED:

grep -Po "(?<=<cite>).*?(?=</cite>)" /tmp/file.txt | sed 's:<[^>]*>::g' 

将删除之间的一切<...>

2

可以通过管道将您的grep这个sed删除所有<strong></strong>标签:

sed -r 's#</?strong>##g' 
2

尝试:

echo "<strong>site.com</strong>/<strong>blahblah</strong>/foo" | sed -e 's/<strong>//g' -e 's/<\/strong>//g' 

输出

site.com/blahblah/foo