0

How do I parse a xml line for ExtData tags, which has some complex value, I need to mask it like this : For eg:

<ExtData>Name="Jason" Value="Special"</ExtData>
to
<ExtData>Name="Jason" Value="XXXXXXX"</ExtData>

I need to mask ExtData tag value like above only when Name is Jason or some set of name, and not for every Name.

For eg: if "DummyName" is not in set of names, than I do not want to change this below line.

<ExtData>Name="DummyName" Value="Garbage"</ExtData>

I need to do all this in bash/shell script.

Bottom line is, I want to read a file line by line, say, via sed command. Check for ExtData tag in the line. If matched, Read the text between ExtData tag and /ExtData tag. In this text, extract Name. If Name is from a set of names, then mask its corresponding "Value" data with equal number of 'X'.

Please let me know how to achieve the above task.

Thanks !! Puneet

Puneet Jain
  • 97
  • 1
  • 10
  • Please don't repost a subset of a question you asked 16 hours earlier and got no replies. Improve that question by editing it instead. Thanks. – kjhughes Aug 04 '16 at 20:08
  • Hint: Use a real XML processor such as [xmlstarlet](http://xmlstar.sourceforge.net/) rather than text processor. – kjhughes Aug 04 '16 at 20:10
  • @kjhughes Ok. I updated the original question.... Actually in the original question, the 1st part was solved, and only 2nd part was un-answered. So, i thought of posting the 2nd part as a new question. And actually, I cannot use xmlstarlet, because the script I am trying to running is on a production server which has bare minimum s/w installed. I mean, i can do it, but i have to go through a lot of channel to get it done. Hence I prefer simple bash script. – Puneet Jain Aug 04 '16 at 20:33
  • You should only post a single question in your question to start with, and then post the answer if you figure it out before anyone else answers. – kjhughes Aug 04 '16 at 20:38
  • Any solution not involving a real XML parser will intrinsically be brittle. Not recommended. – kjhughes Aug 04 '16 at 20:38
  • @kjhughes Thanks. I updated my original question. XML parser usage would be tough in my server. Do you mind suggesting me how to do it via a bash script please? – Puneet Jain Aug 04 '16 at 20:48
  • No, sorry, I would be doing you a disservice to direct you in that manner. – kjhughes Aug 04 '16 at 21:21

0 Answers0