I use xmlstarlet el -v to display the structure of an XML file, including all attributes and values. I would like to convert its output to some key-value pairs, i.e. Each attribute with its own value on a separate line (including XPath); Each row must be unique.
Current result:
topRoot/topSystem/commSvcEp/commSyslog[@descr='Syslog Service' and @name='syslog' and @policyOwner='local' and @severity='critical'] topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[@adminState='disabled' and @forwardingFacility='local7' and @hostname='none' and @name='secondary' and @severity='critical'] topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[@adminState='disabled' and @forwardingFacility='local7' and @hostname='none' and @name='tertiary' and @severity='critical'] topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[@adminState='disabled' and @forwardingFacility='local7' and @hostname='none' and @name='primary' and @severity='critical']
Desired result (maybe anything, indexes are just an idea):
topRoot/topSystem/commSvcEp/ commSyslog@descr ='Syslog Service' topRoot/topSystem/commSvcEp/ commSyslog@name ='syslog' topRoot/topSystem/commSvcEp/ commSyslog@policyOwner ='local' topRoot/topSystem/commSvcEp/ commSyslog@severity ='critical' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[0]@adminState='disabled' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[0]@forwardingFacility='local7' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[0]@hostname='none' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[0]@name='secondary' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[0]@severity='critical' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[1]@adminState='disabled' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[1]@forwardingFacility='local7' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[1]@hostname='none' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[1]@name='tertiary' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[1]@severity='critical' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[2]@adminState='disabled' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[2]@forwardingFacility='local7' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[2]@hostname='none' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[2]@name='primary' topRoot/topSystem/commSvcEp/commSyslog/commSyslogClient[2]@severity='critical'
What I'm trying to do can run diff on top of two such files, or use grep to filter matching patterns. I am sure there is a way to create such output without using sed , awk or anything else other than xmlstarlet .
I am pretty new to xmlstarlet and the world of xml (not only because I don't like xml because of its complexity and parsing overhead, etc.), so I am very grateful for your help. Thanks!
source share