开发者

Remove links from text file

how can I remove links from a raw html text? I've got:

Foo bar <a href="http://www.foo.开发者_StackOverflowcom">blah</a> bar foo 

and want to get:

Foo bar blah bar foo

afterwards.


You're looking to parse HTML with regexps, and this won't work in all but the simplest cases, since HTML isn't regular. A much more reliable solution is to use an HTML parser. Numerous exist, for many different languages.


sed -re 's|<a [^>]*>([^<]*)</a>|\1|g'

But Brian's answer is right: This should only be used in very simple cases.


try with:

sed -e 's/<a[^>]*>.*<\/a>//g' test.txt


$ echo 'Foo bar <a href="http://www.foo.com">blah</a> bar foo' | awk 'BEGIN{RS="</a>"}/<a href/{gsub(/<a href=\042.*\042>/,"")}1'

Foo bar blah bar foo

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜