Re: A Simple Text-Region Deletion Question . . .

"Ronaldo Ferreira de Lima [email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <20141004221349.GA1128@textmode>
Greetings Marcus,


On Fri, Oct 03, 2014 at 08:44:36PM -0400, 'Marcus L. Thompson' [email protected] wrote:
> Greetings to all.
> 
> I have come across what seems to be a quite simple problem involving an
> application of sed in the context of text-block deletion. Here's the
> hypothetical text block in question:
> 
> <property name="name">
> ...
> </property>
> </property>
> 
> Now, deleting all from <property name="name"> to the _/first/_
> </property> tag is understandable enough:
> 
> Code:
> 
> sed -i '/<property name="name">*$/,/<\/property>*$/d' /file.xml
> 
> However, incorporating the 2nd </property> tag in the deletion sweep is
> a bit tougher; and just that much outside my new skillset range ;o)
> 
> Any ideas as to how one might amend this "one-liner" to make it all work?
You might try:


    $ sed '/<property name="name">/{:loop;/<\/property>.*<\/property>/{s/.*//;b;};N;b loop;};' file.xml


But this is not a good approach to edit XML files. Have a look in XML
parsers like xmllint or xsh (command-line applications).
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.