In xml file I am searching the sting "<file:write" and xml file has a complete xml tag and with in that tag it has the value field. I am trying to fetch the value filed in csv file with file name. The problem is that the field (path= and Path=) is either 2 or 3 or 4th column and I am not able to use the cut command.
Is there a better way of doing this?
find /opt/mortagage/application.xml -type f -exec egrep -ri "<file:write" /dev/null {} + |uniq| sed '/<!--.*-->/d' | sed '/<!--/,/-->/d'
/opt/mortagage/application.xml: <file:write doc:id="16630" path="${file.location}" doc:name="Save file to directory">
/opt/mortagage/application.xml: <file:write doc:name="Write to complete folder" doc:id="18890" path='#["${file.completeLocation}" ++ vars.zipFileName]' config-ref="File_Config_completed">
/opt/mortagage/application.xml: <file:write doc:name="Write to complete folder" doc:id="19990" Path='#["${file.completeLocation}" ++ vars.zipFileName]' config-ref="File_Config_completed">
Using kislyuk/yq:
Using mikefarah/yq (which completely ignores namespaces):
Using xmlstarlet:
Using libxml/xmllint:
xmllintrequires to either declare the actual namespaces (which you haven't provided in the sample), or to defect to ignoring them all by resorting to alocal-name()checkxmllintalso doesn't support thestring(…)function on multiple matches, so the best it can do is to output full attribute nodes likepath="${file.location}". A workaround could be to subsequently use another tool (likeawkorsed) to trim them down.All of them output something like: