4

Is there a way to do this in Ubuntu? I've read it's possible in php, but I'm not familiar with php at all.

2 Answers 2

3

You could use sed for that, but it will only work for links that are in a single line in the html code.

Update:

Damn greedy regex! ;) This one should work now!

sed -i 's|<a[^>]\+>|<a>|g' <the-html-file>

5
  • It's behaving oddly! Deleting all the sentences, after a link anchor in a paragraph till next link anchor, which is not being removed. Leaving many links as is. :( May 29, 2013 at 19:56
  • Can you give a Sample file?
    – ortang
    May 29, 2013 at 20:10
  • I have updated my answer
    – ortang
    May 30, 2013 at 12:42
  • 1
    Damn! It's working like a knife on cheese. Thanks a lot. It will be highly educational if you can add the description of "Greedy regex" to the answer. May 30, 2013 at 15:09
1

Depends what you are trying to do:

If you have a pile of files on your machine, and you want to remove the links, use something like a wee perl script to remove the <a ...> ... </a> tags. You can remove other tags (or even all tags) in a similar way. With the right pattern matching options, this approach can handle tags split across multiple lines. (It's very elegant, but the details won't fit in the margin of this post).

If you are trying to browse files on some webserver, using firefox (or other browser), some kind of greasemonkey script that automatically modifies pages on the fly, before showing them, might be what you want.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .