How do I parse a log file (not a full xml file, but it has some portion of xml data) for ExtData tags, which has some name-value pair, 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>
For eg: if "DummyName" is not in set of names, than I do not want to change this below line. (Please note that the value is "Jason")
<ExtData>Name="DummyName" Value="Jason"</ExtData>
For eg: if "DummyJasonName" is not in set of names, than I do not want to change this below line. (Note "Jason" in between "Dummy" and "Name")
<ExtData>Name="DummyJasonName" Value="Garbage"</ExtData>
I need to do all this in bash/shell script.
Bottom line is, I want to read a file, say, via sed/awk/match command.
Check for ExtData tag in the line. If matched, Read the text between ExtData tag and /ExtData tag. In this multiline 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.
Update, the input line can actually span over multiple lines.
<ExtData>Name="Jason"
Value="Special"
</ExtData>
Or like this too:
<ExtData>
Name="Jason"
Value="Special"
</ExtData>
Thanks !! Puneet
See Question&Answers more detail:
os