4 ms·
sed really is a powerful utility. I once wrote a tool in sed that strips HTML tags leaving just plain text as a fun exercise. Naturally it can't handle complica
by kccqzy 8y ago
sed really is a powerful utility. I once wrote a tool in sed that strips HTML tags leaving just plain text as a fun exercise. Naturally it can't handle complicated cases but for many simple use cases it works. The code, though, is basically unreadable.
- airstrike 8y agoAny chance you could share that? Wouldn't mind giving it a whirl in this one side project I just started...
- james_s_tayler 8y agoI used to write web scrapers with curl/grep/sed back in the day. Fun times.
- saagarjha 8y agoGiven that sed is Turing complete, I'm sure if you tried harder you would have come up with a general solution ;)
- mannykannot 8y agoAbsolutely. One approach would be to take this TM implementation and program it to parse HTML.
- mirimir 8y agoIsn't it more or less a cliche that using sed etc for stripping HTML tags is unreliable and potentially hazardous? I've tried it. I could get it to apparently "work". But then I'd get some input that hosed it. Now I just use "w3m -dump". I mean, it's a browser.
- mannykannot 8y agoThe unreliability follows from it being "basically unreadable", which leads to it probably not doing what you intend. Whether it is hazardous depends on what you use it for.
- noxToken 8y agoThere's the classic Stack Overflow answer[0] about matching HTML tags. If you have a small subset of HTML, it can work out pretty well. [0]: https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 https://stackoverflow.com/questions/1732348/regex-match-open...
- mirimir 8y agoThanks. That's what I was thinking of. Classic "this parrot is dead" riff.
- somacert 8y agosed -e 's/<[^>]*>//g'