1

Im stucked. Ive got html files with:

Lorem ipsum Lorem ipsum
Lorem ipsum 
Lorem ipsum 
Random text123 </td></tr></table><a name="Preamble"</a> Random text
Lorem ipsum Lorem ipsum 123
Lorem ipsum 125
Lorem ipsum

I need:

Random text
Lorem ipsum Lorem ipsum 123
Lorem ipsum 125
Lorem ipsum

I used:

sed 's/.*<.td><.tr><.table><a\ name\=.*><.a>//g'

but it cuts only chars in this line, not text before (also i think //g is cutting all matched patterns in doc, I need only first occurence).

Second question: Ive got huge file like:

Lorem ipsum Lorem ipsum 
Lorem ipsum Lorem ipsum
Lorem ipsum 
Lorem ipsum
Lorem ipsum<tag>Text that need to be changed 
Text that need to be changed by multiple seds
Text that need to be changed Text that need to be changed by multiple sed
Text that need to be changed 
Text that need to be changed </tag>Lorem ipsum
Lorem ipsum Lorem ipsum 
orem<tag>Text that need to be changed 
Text that need to be changed by multiple seds
Text that need to be changed Text that need to be changed by multiple sed
Text that need to be changed 
Text that need to be changed </tag>Lorem ipsum

I need to use multiple sed only on sectors started with and ended with how to do that? Thanks for any reply!

  • 2
    Regular expressions are not meant for html or xml parsing. It's too easy to find examples where typical attempts fail. There are powerful tools for text processing in *ml files or libraries for python, for example. If you are sure about what you are doing, at least do things like <a name=[^>]*> to avoid hopping to the wrong tag end – Philippos Sep 10 at 8:43
  • 1
    Some html tags in a file does not make (valid) html. Your examples are bad. Try BeautifulSoup. – pLumo Sep 10 at 11:51

Your Answer

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

Browse other questions tagged or ask your own question.