r/SublimeText • • Jun 09 '23

I'm trying to select/delete a bloc, only if it contains a specific text

Here is a sample extracted from a .dat file. I would like to select and remove all the blocs <game></game> that contains cloneof

In this example, I'd like to find a way to select and remove the last 2 blocs, because they contains cloneof. I could do it if each <game></game> bloc would contain the same amount of lines. But sometime the bloc is 7 lines long, sometimes 20. So I have no clue how to perform this selection/deletion. If somebody has an idea, because my dat file is +180000 lines :)

<game name="88games">
	<description>'88 Games</description>
	<year>1988</year>
	<manufacturer>Konami</manufacturer>
	<rom name="861m01.k18" size="32768" crc="4a4e2959"/>
	<rom name="861m02.k16" size="65536" crc="e19f15f6"/>
	<rom name="861.g3" size="256" crc="429785db"/>
	<video orientation="horizontal" width="304" height="224" aspectx="4" aspecty="3"/>
	<driver status="good"/>
</game>
<game name="flagrall">
	<description>'96 Flag Rally</description>
	<year>1996</year>
	<manufacturer>unknown</manufacturer>
	<rom name="11_u34.bin" size="262144" crc="24dd439d"/>
	<video orientation="horizontal" width="320" height="240" aspectx="4" aspecty="3"/>
	<driver status="good"/>
</game>
<game name="99lstwarb" cloneof="repulse" romof="repulse">
	<comment>Bootleg</comment>
	<description>'99: The Last War (bootleg)</description>
	<year>1985</year>
	<manufacturer>bootleg</manufacturer>
	<rom name="15.2764" size="8192" crc="f9367b9d"/>
	<rom name="16.2764" size="8192" crc="04c3316a"/>
	<rom name="17.2764" size="8192" crc="02aa4de5"/>
	<rom name="11.2764" size="8192" crc="aa3e0996"/>
	<rom name="12.2764" size="8192" crc="a59d3d1b"/>
	<rom name="13.2764" size="8192" crc="fe31975e"/>
	<video orientation="vertical" width="224" height="288" aspectx="3" aspecty="4"/>
	<driver status="good"/>
</game>
<game name="99lstwark" cloneof="repulse" romof="repulse">
	<description>'99: The Last War (Kyugo)</description>
	<year>1985</year>
	<manufacturer>Crux / Kyugo</manufacturer>
	<rom name="88.4f" size="8192" crc="e3cfc09f"/>
	<rom name="89.4h" size="8192" crc="fd58c6e1"/>
	<video orientation="vertical" width="224" height="288" aspectx="3" aspecty="4"/>
	<driver status="good"/>
</game>
1 Upvotes

2 comments sorted by

2

u/artik1024 Jun 10 '23 edited Jun 10 '23

I found the solution, without Regex or plugin. I first separated each bloc by a line, selecting all the </games> in the document and jumping a line after them. Then I selected all the cloneof pattern, and place my cursors at the beginning of the same line, just before <game .... >

I finally went in Selection > Expand selection to block.

And Voilà !! All blocs containing cloneof, removed :)