替换文本文件模式 [英] replace pattern in text file
本文介绍了替换文本文件模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面我的样本HTML文件:
Below my sample html file:
some text here <img src="http://site.com/7b399e20/77165/5fa/2a31ffb8.jpg"/> sometext here
some text here <img src="http://site.com/7b399e20/2a31ffb8.jpg"/> sometext here
some text here <img src="http://site.com/7b399e20/2a31ffb8.png"/> sometext here
some text here <img src="http://site.com/2a31ffb8.jpeg"/> sometext here
我怎么做出这样的转变:
how do I make such a transformation:
some text here <img src="web/2a31ffb8.jpg"/> sometext here
some text here <img src="web/2a31ffb8.jpg"/> sometext here
some text here <img src="web/2a31ffb8.png"/> sometext here
some text here <img src="web/2a31ffb8.jpeg"/> sometext here
感谢
推荐答案
我将使用Perl,因为我知道的语法,而无需看它,但它会在AWK非常相似或sed的,因为tekknolagi说:
I'll use Perl, because I know the syntax without having to look it up, but it would be very similar in awk or sed, as tekknolagi says:
perl -pi -e 's|http://site.com/.*([^/]+)"/>|web/$1"/>|;' <filename>
这将美元最后夹住的p $ pserve一切/和
This will preserve everything between the last / and the "
这篇关于替换文本文件模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文