I have a file that has lots of XML nodes:
<output>
<file name="user.java">
</file>
<file name="random.java">
<error line="52" column="3" severity="warning" message="User is not found." source="randomSource"/>
</file>
<output/>
Now I need to replace the source
in the error node with the name
attribute in the file and print it to a file. So the output file should have only
rows of error:
<error line="52" column="3" severity="warning" message="User is not found." name="customer.java"/>
preferably the name should be the first attribute:
<error name="random.java" line="52" column="3" severity="warning" message="User is not found." />
So the new file should only contain the error nodes and I can only use the default tools such as sed/awk/cut/etc...
I have only got as far as printing the error line but can't figure out how to do the above:
awk -vtag=file -vp=0 '{
if($0~("^<"tag)){p=1;next}
if($0~("^</"tag)){p=0;printf("\n");next}
if(p==1){$1=$1;printf("%s",$0)}
}' infile