Skip to content

Instantly share code, notes, and snippets.

@eoldavix
Created December 12, 2017 10:53
Show Gist options
  • Select an option

  • Save eoldavix/498629fc837a8725a1b4638b903c07f5 to your computer and use it in GitHub Desktop.

Select an option

Save eoldavix/498629fc837a8725a1b4638b903c07f5 to your computer and use it in GitHub Desktop.
Get last multiline occurrence in a file
#!/bin/bash
tac < test.xml | sed '/<\/food>/,$!d;/<food/q' | tac
<breakfast_menu>
<food one>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food other>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
<food any>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
<calories>900</calories>
</food>
<food some>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>
<!-- I want this part -->
<food whatever>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>
<!-- I want this part -->
</breakfast_menu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment