Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep, awk, egrep ...

Status
Not open for further replies.

cmarchman

Programmer
Jun 18, 2004
56
US
Here's the problem: I've got a large .xml file that has many different <tags> within a single line, however some of the data between the <tags> have line spacing in them. Some sample <tags> are;
<VulnerabilityID></VulnerabilityID><Severity></Severity><Summary>


</Summary><Execution></Execution>......

I'm able to grep for information on the line until the line break of the Summary tag. I would like to pull the info that is between the <Summary> and the </Summary> tags.

Is this done with grep, awk, egrep etc.

Thanks,
 
Does this awk cript do that you want?

n{a[++n]=$0}
/<Summary>/{
gsub(/.*<Summary>/,"")
n = 1
a[n] = $0
}
/<\/Summary>/ && n{
gsub(/<\/Summary>.*/,"")
for (j=1;j<n;j++) print a[j]
print
n=0
}

CaKiwi
 
CaKiwi,

That code worked great at pulling the <Summary> data out, thanks. However, I need a way of associating that part with the <VulnerabilityID> that is in the same line as the <Summary> tag. Maybe a parsed variable of the <VulnerabilityID> tag. Hmmm, I wonder if that would work.

Thanks,

cmarchman
 
CaKiwi,

You headed me in the right direction and I've got the rest figured out. Since the <VulnerabilityID> and the <Summary> tags are on the same line, I simply substituted every instance of <Summary> within the code you provided with the <VulnerabilityID> tag and therefore was able to pull all of the necessary data I need from the files. Works great!!!

Thanks a million (if that's worth much nowadays),

cmarchman
 
You may want to look for an open-source tool called [tt]xsh[/tt]; it's an "XML shell," and it's designed for editing XML files. You can write scripts in it like in any other shell. If you plan to do a lot of scripting work with these XML files, you may find that a handy alternative.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top