0

We have a file which has unformatted xml content in a single line

<sample:text>Report</sample:text><sample:user name="11111111" guid="163g673"/><sample:user name="22222222" guid="aknen1763y82bjkj18"/><sample:user name="33333333" guid="q3k4nn5k2nk53n6"/><sample:user name="44444444" guid="34bkj3b5kjbkq"/><sample:user name="55555555" guid="k4n5k34nlk6n711kjnk5253"/><sample:user name="66666666" guid="1n4k14nknl1n4lb1"/>

If we find a particular string suppose "22222222", i want to remove the entire string that surrounds the matched string. In our case the entire portion around 22222222 i.e., <sample:user name="22222222" guid="aknen1763y82bjkj18"/> should be removed and the file has to be saved.

How can we do it? Please help

4
  • 6
    See if you've ever acknowledged users by accepting their answers for your questions. stackoverflow.com/users/533315/abhinav?tab=questions Commented May 18, 2018 at 6:34
  • 2
    @Inian: Your comment is spot on; this one really surprised me, especially considering many would probably feel honored having Jon Skeet personally answer one of their questions. Commented May 18, 2018 at 7:14
  • 1
    @l'L'l Then again, it's more probable to have had him answer you than for example me. :D Commented May 18, 2018 at 8:18
  • @l'L'l .. I dunno. Jon Skeet didn't get a SO score of >1million just by providing high quality answers. As of this writing, Jon has posted 34140 answers to StackOverflow questions. I'm actually sometimes surprised that I come across them so infrequently ... though of course, I never look at Jon's highest-grossing tags. Commented May 18, 2018 at 14:02

1 Answer 1

2

You can do it using sed utility by invoking it like this:

sed -i file -e 's/<[^<]*"22222222"[^>]*>//'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.