2012-03-19 113 views
3

我试图用"<br>"替换“\ n”,但是没有找到如何在tr上使用<>。任何想法做这个命令的工作:带特殊字符的tr命令

echo "HTML example<br>Print new line<br>please<br>not work" | tr "<br>" "\n" 

编辑

FatalError回答没有为我的OSX狮子工作。我不知道为什么,但这个简单的sed命令不作新的生产线,它仅仅返回

HTML examplenPrint new linenpleasennot work 

我使用GNU的bash,版本3.2.48(1)-release下(x86_64-苹果darwin11) 。 有没有其他想法?

回答

5

tr用于将字符映射到其他字符。对于这个任务,我建议使用sed

echo "HTML example<br>Print new line<br>please<br>not work" | sed -e 's/<br>/\n/g' 

这告诉sed替代的<br>每个实例有一个换行符字符。

编辑

如果你有问题,因为/ \在SED,这将解决这个问题

echo "HTML example<br>Print new line<br>please<br>not work" | sed -e "s/<br>/\\`echo -e '\n\r'`/g" 
+0

+1通过了15秒。 – MattH 2012-03-19 14:59:27

+0

真棒答案打我... – Teja 2012-03-19 14:59:35

+0

我也是:-)删除... – Birei 2012-03-19 15:00:59