I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help
Basically, the file will be a collection of huge no of xmls each in a different line and the tag will not span multiple lines. I actually want a generic method to do this i.e. the command should scan for "object1" tag and should extract the value between <object1> and </object1> and display all the xmls containing this particular value and its count.
---------- Post updated at 02:25 AM ---------- Previous update was at 02:21 AM ----------
Hey, this works perfectly. Thanks. However, can you suggest a generic method to do this . I wanna search for the "object1" tag in the xml and copy its tag value and display all lines containing this value and its count. Can you explain ur command a bit so i can understand the code. I want to extrapolate this command later so that i can search for other tag values and display content accordingly.
c[$5]++ creates a associative array c[] with field #5 as the key and increments the value (c[house]=c[house]+1) so it's a count of the number of times each tag appears.
d[$5] = d[$5] ? d[$5] ORS $0 : $0 if d[$5] is not null/blank then append ORS (output record separator which is newline in this case) and while input line to it; otherwise assign it to the whole input line.
The END block goes through all the keys in the d[] array and prints the key count followed by all input lines that contain that key (value of the d[] array element).
Yes, this is working fine. thanks. I ran into another problem. Actually before the xml starts, there is some string. I need to run this awk script only on those lines which have the string "Exception Found" before the xmls. I guess i have to add && /Exception Found/, but im confused where to add it in this awk script.