Skip to main content
1 of 3
Stéphane Chazelas
  • 585.1k
  • 96
  • 1.1k
  • 1.7k

If the file were correct xml, you could use an xml parsing tool. Otherwise, assuming there's no other (nested) div section inside that section, you could do:

pcregrep -Mo '(?s)<div[^>]*id="id1".*?</div>' the-file.html
Stéphane Chazelas
  • 585.1k
  • 96
  • 1.1k
  • 1.7k