0

I have a file that is mixed with both normal text I need and html-tags. I know that with REGEX it is possible to recognize html tags and with sed one can swap those for an empty string, but I do not know how to apply it concretely.

  • 6
    sed is not good tool to remove html tags. – jimmij Feb 16 '15 at 13:16
  • would it be possible to provide some samples? Are you looking to extract information from an XML file or cleanup some XML content within another file? Your choice of tool depends on what you are trying to achieve. – rahul Feb 16 '15 at 13:18
  • 8
    Obligatory: stackoverflow.com/questions/1732348/… – muru Feb 16 '15 at 13:45
  • Down that path lies madness. – yellowantphil Feb 16 '15 at 16:33
2

As long as your HTML tags are confined to a single line, the following will work:

sed 's/<[^>]*>//g'
7

If you are not insisting on sed, the best thing to do this would be lynx.

lynx --dump <filename>.html

This will output the content of the html file in the format the html code was intending to display. The only condition is that the filename should have a .html or .htm extension.

3

I strongly recommend the use of either of the programs named html2text (1) (2) instead. Parsing HTML is much harder than it looks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.