adding comment tag on XML file through unix

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












-2















INPUT XML FILE:



<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<Dcn xmlns="http://schemas.test.com/2013/ClaimRequest" xsi:schemaLocation="http://schemas.test.com/2013/ClaimRequest gdhjf/profiles/Redirect/dhd/Desktop/dhd_Prof.XSD" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header sendingSystemId="XYC" receivingSystemId="ABC" version="2.0" createDateTime="2019-01-19T04:27:15" batchingControlNumber="AZ042018" transType="ClaimRequest" dcn="1901959351"/>
<Body>
<ClaimRequest>
<Claims>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180409120000102" claimEndDate="2018-04-02" claimStartDate="2018-04-02" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="54321"/>
<Patient eligSysId="dhhgs1" clientId="VBV"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1" />
<ClaimLine sourceSystemClaimLineNumber="2" />
<ClaimLine sourceSystemClaimLineNumber="3" />
</ClaimLines>
<ClaimTrailer claimDetailLineCount="3"/>
</ProfessionalClaim>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180430120000277" claimEndDate="2018-04-12" claimStartDate="2018-04-12" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="54673"/>
<Patient eligSysId="dhhgs1" clientId="VBV"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1" />
</ClaimLines>
<ClaimTrailer claimDetailLineCount="1"/>
</ProfessionalClaim>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180430120000279" claimEndDate="2018-04-17" claimStartDate="2018-04-17" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="676543"/>
<Patient lastName="CLARK" memberId="U1672936601" firstName="DANIEL" eligSysId="CNCIEDW1" clientId="CNC"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1" />
<ClaimLine sourceSystemClaimLineNumber="2" />
</ClaimLines>
<ClaimTrailer claimDetailLineCount="2"/>
</ProfessionalClaim>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180430120000281" claimEndDate="2018-04-17" claimStartDate="2018-04-17" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="653473"/>
<Patient lastName="VAUGHN" memberId="U1677077501" firstName="KAREN" eligSysId="CNCIEDW1" clientId="CNC"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1"/>
<ClaimLine sourceSystemClaimLineNumber="2"/>
</ClaimLines>
<ClaimTrailer claimDetailLineCount="2"/>
</ProfessionalClaim>
</Claims>
<IcnCount total="4"/>
</ClaimRequest>
</Body>
</Dcn>


I have to add comment tag before the header tag in this XML file with the following details populated.



<!-- Claims Paid_Start_Date="2018-04-02" Paid_End_Date="2018-04-17" Process_Start_Date="20180409" Process_End_Date="201804301" -->


Here,



  • Claim_Start_Date= MINIMUM of claimsStartDate from the file.

  • Claim_End_Date= MAXIMUM of claimEndDate from the file

  • Process_Start_Date= First claimprocessedDateTime from the file

  • Process_End_Date= Last claimProcessedDateTime from the file

This is what I have done so far:



F_LINE=awk '/<professionalclaim/' test.xml | head -1



L_LINE=awk '/<professionalclaim/' test.xml | tail -1



Now I need to pull the required values from these two lines and populate in comment tag.










share|improve this question
























  • Hello Velava Shanmugam. It seems there are two issues here: (1) you need to parse and process the file to get the values for the comment, (2) you need to add the comment to the file. What have you tried so far?

    – roaima
    Jan 21 at 20:00












  • I have just captured the first and last line that matches the string "<ProfessionalClaim " and stored them in to one variable each. F_LINE=awk '/<ProfessionalClaim/' test.xml | head -1 L_LINE=awk '/<ProfessionalClaim/' test.xml | tail -1

    – Velava Shanmugam
    Jan 22 at 2:40











  • Thanks! Its done. I have updated the question

    – Velava Shanmugam
    Jan 22 at 17:25















-2















INPUT XML FILE:



<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<Dcn xmlns="http://schemas.test.com/2013/ClaimRequest" xsi:schemaLocation="http://schemas.test.com/2013/ClaimRequest gdhjf/profiles/Redirect/dhd/Desktop/dhd_Prof.XSD" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header sendingSystemId="XYC" receivingSystemId="ABC" version="2.0" createDateTime="2019-01-19T04:27:15" batchingControlNumber="AZ042018" transType="ClaimRequest" dcn="1901959351"/>
<Body>
<ClaimRequest>
<Claims>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180409120000102" claimEndDate="2018-04-02" claimStartDate="2018-04-02" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="54321"/>
<Patient eligSysId="dhhgs1" clientId="VBV"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1" />
<ClaimLine sourceSystemClaimLineNumber="2" />
<ClaimLine sourceSystemClaimLineNumber="3" />
</ClaimLines>
<ClaimTrailer claimDetailLineCount="3"/>
</ProfessionalClaim>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180430120000277" claimEndDate="2018-04-12" claimStartDate="2018-04-12" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="54673"/>
<Patient eligSysId="dhhgs1" clientId="VBV"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1" />
</ClaimLines>
<ClaimTrailer claimDetailLineCount="1"/>
</ProfessionalClaim>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180430120000279" claimEndDate="2018-04-17" claimStartDate="2018-04-17" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="676543"/>
<Patient lastName="CLARK" memberId="U1672936601" firstName="DANIEL" eligSysId="CNCIEDW1" clientId="CNC"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1" />
<ClaimLine sourceSystemClaimLineNumber="2" />
</ClaimLines>
<ClaimTrailer claimDetailLineCount="2"/>
</ProfessionalClaim>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180430120000281" claimEndDate="2018-04-17" claimStartDate="2018-04-17" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="653473"/>
<Patient lastName="VAUGHN" memberId="U1677077501" firstName="KAREN" eligSysId="CNCIEDW1" clientId="CNC"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1"/>
<ClaimLine sourceSystemClaimLineNumber="2"/>
</ClaimLines>
<ClaimTrailer claimDetailLineCount="2"/>
</ProfessionalClaim>
</Claims>
<IcnCount total="4"/>
</ClaimRequest>
</Body>
</Dcn>


I have to add comment tag before the header tag in this XML file with the following details populated.



<!-- Claims Paid_Start_Date="2018-04-02" Paid_End_Date="2018-04-17" Process_Start_Date="20180409" Process_End_Date="201804301" -->


Here,



  • Claim_Start_Date= MINIMUM of claimsStartDate from the file.

  • Claim_End_Date= MAXIMUM of claimEndDate from the file

  • Process_Start_Date= First claimprocessedDateTime from the file

  • Process_End_Date= Last claimProcessedDateTime from the file

This is what I have done so far:



F_LINE=awk '/<professionalclaim/' test.xml | head -1



L_LINE=awk '/<professionalclaim/' test.xml | tail -1



Now I need to pull the required values from these two lines and populate in comment tag.










share|improve this question
























  • Hello Velava Shanmugam. It seems there are two issues here: (1) you need to parse and process the file to get the values for the comment, (2) you need to add the comment to the file. What have you tried so far?

    – roaima
    Jan 21 at 20:00












  • I have just captured the first and last line that matches the string "<ProfessionalClaim " and stored them in to one variable each. F_LINE=awk '/<ProfessionalClaim/' test.xml | head -1 L_LINE=awk '/<ProfessionalClaim/' test.xml | tail -1

    – Velava Shanmugam
    Jan 22 at 2:40











  • Thanks! Its done. I have updated the question

    – Velava Shanmugam
    Jan 22 at 17:25













-2












-2








-2








INPUT XML FILE:



<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<Dcn xmlns="http://schemas.test.com/2013/ClaimRequest" xsi:schemaLocation="http://schemas.test.com/2013/ClaimRequest gdhjf/profiles/Redirect/dhd/Desktop/dhd_Prof.XSD" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header sendingSystemId="XYC" receivingSystemId="ABC" version="2.0" createDateTime="2019-01-19T04:27:15" batchingControlNumber="AZ042018" transType="ClaimRequest" dcn="1901959351"/>
<Body>
<ClaimRequest>
<Claims>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180409120000102" claimEndDate="2018-04-02" claimStartDate="2018-04-02" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="54321"/>
<Patient eligSysId="dhhgs1" clientId="VBV"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1" />
<ClaimLine sourceSystemClaimLineNumber="2" />
<ClaimLine sourceSystemClaimLineNumber="3" />
</ClaimLines>
<ClaimTrailer claimDetailLineCount="3"/>
</ProfessionalClaim>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180430120000277" claimEndDate="2018-04-12" claimStartDate="2018-04-12" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="54673"/>
<Patient eligSysId="dhhgs1" clientId="VBV"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1" />
</ClaimLines>
<ClaimTrailer claimDetailLineCount="1"/>
</ProfessionalClaim>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180430120000279" claimEndDate="2018-04-17" claimStartDate="2018-04-17" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="676543"/>
<Patient lastName="CLARK" memberId="U1672936601" firstName="DANIEL" eligSysId="CNCIEDW1" clientId="CNC"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1" />
<ClaimLine sourceSystemClaimLineNumber="2" />
</ClaimLines>
<ClaimTrailer claimDetailLineCount="2"/>
</ProfessionalClaim>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180430120000281" claimEndDate="2018-04-17" claimStartDate="2018-04-17" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="653473"/>
<Patient lastName="VAUGHN" memberId="U1677077501" firstName="KAREN" eligSysId="CNCIEDW1" clientId="CNC"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1"/>
<ClaimLine sourceSystemClaimLineNumber="2"/>
</ClaimLines>
<ClaimTrailer claimDetailLineCount="2"/>
</ProfessionalClaim>
</Claims>
<IcnCount total="4"/>
</ClaimRequest>
</Body>
</Dcn>


I have to add comment tag before the header tag in this XML file with the following details populated.



<!-- Claims Paid_Start_Date="2018-04-02" Paid_End_Date="2018-04-17" Process_Start_Date="20180409" Process_End_Date="201804301" -->


Here,



  • Claim_Start_Date= MINIMUM of claimsStartDate from the file.

  • Claim_End_Date= MAXIMUM of claimEndDate from the file

  • Process_Start_Date= First claimprocessedDateTime from the file

  • Process_End_Date= Last claimProcessedDateTime from the file

This is what I have done so far:



F_LINE=awk '/<professionalclaim/' test.xml | head -1



L_LINE=awk '/<professionalclaim/' test.xml | tail -1



Now I need to pull the required values from these two lines and populate in comment tag.










share|improve this question
















INPUT XML FILE:



<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<Dcn xmlns="http://schemas.test.com/2013/ClaimRequest" xsi:schemaLocation="http://schemas.test.com/2013/ClaimRequest gdhjf/profiles/Redirect/dhd/Desktop/dhd_Prof.XSD" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header sendingSystemId="XYC" receivingSystemId="ABC" version="2.0" createDateTime="2019-01-19T04:27:15" batchingControlNumber="AZ042018" transType="ClaimRequest" dcn="1901959351"/>
<Body>
<ClaimRequest>
<Claims>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180409120000102" claimEndDate="2018-04-02" claimStartDate="2018-04-02" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="54321"/>
<Patient eligSysId="dhhgs1" clientId="VBV"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1" />
<ClaimLine sourceSystemClaimLineNumber="2" />
<ClaimLine sourceSystemClaimLineNumber="3" />
</ClaimLines>
<ClaimTrailer claimDetailLineCount="3"/>
</ProfessionalClaim>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180430120000277" claimEndDate="2018-04-12" claimStartDate="2018-04-12" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="54673"/>
<Patient eligSysId="dhhgs1" clientId="VBV"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1" />
</ClaimLines>
<ClaimTrailer claimDetailLineCount="1"/>
</ProfessionalClaim>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180430120000279" claimEndDate="2018-04-17" claimStartDate="2018-04-17" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="676543"/>
<Patient lastName="CLARK" memberId="U1672936601" firstName="DANIEL" eligSysId="CNCIEDW1" clientId="CNC"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1" />
<ClaimLine sourceSystemClaimLineNumber="2" />
</ClaimLines>
<ClaimTrailer claimDetailLineCount="2"/>
</ProfessionalClaim>
<ProfessionalClaim paymentIndicator="P" claimProcessedDateTime="20180430120000281" claimEndDate="2018-04-17" claimStartDate="2018-04-17" sourceSystemId="abcd" claimActionCode="00">
<PayToProvider id="653473"/>
<Patient lastName="VAUGHN" memberId="U1677077501" firstName="KAREN" eligSysId="CNCIEDW1" clientId="CNC"/>
<ClaimLines>
<ClaimLine sourceSystemClaimLineNumber="1"/>
<ClaimLine sourceSystemClaimLineNumber="2"/>
</ClaimLines>
<ClaimTrailer claimDetailLineCount="2"/>
</ProfessionalClaim>
</Claims>
<IcnCount total="4"/>
</ClaimRequest>
</Body>
</Dcn>


I have to add comment tag before the header tag in this XML file with the following details populated.



<!-- Claims Paid_Start_Date="2018-04-02" Paid_End_Date="2018-04-17" Process_Start_Date="20180409" Process_End_Date="201804301" -->


Here,



  • Claim_Start_Date= MINIMUM of claimsStartDate from the file.

  • Claim_End_Date= MAXIMUM of claimEndDate from the file

  • Process_Start_Date= First claimprocessedDateTime from the file

  • Process_End_Date= Last claimProcessedDateTime from the file

This is what I have done so far:



F_LINE=awk '/<professionalclaim/' test.xml | head -1



L_LINE=awk '/<professionalclaim/' test.xml | tail -1



Now I need to pull the required values from these two lines and populate in comment tag.







xml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 22 at 18:34









Rui F Ribeiro

40k1479135




40k1479135










asked Jan 21 at 19:50









Velava ShanmugamVelava Shanmugam

36




36












  • Hello Velava Shanmugam. It seems there are two issues here: (1) you need to parse and process the file to get the values for the comment, (2) you need to add the comment to the file. What have you tried so far?

    – roaima
    Jan 21 at 20:00












  • I have just captured the first and last line that matches the string "<ProfessionalClaim " and stored them in to one variable each. F_LINE=awk '/<ProfessionalClaim/' test.xml | head -1 L_LINE=awk '/<ProfessionalClaim/' test.xml | tail -1

    – Velava Shanmugam
    Jan 22 at 2:40











  • Thanks! Its done. I have updated the question

    – Velava Shanmugam
    Jan 22 at 17:25

















  • Hello Velava Shanmugam. It seems there are two issues here: (1) you need to parse and process the file to get the values for the comment, (2) you need to add the comment to the file. What have you tried so far?

    – roaima
    Jan 21 at 20:00












  • I have just captured the first and last line that matches the string "<ProfessionalClaim " and stored them in to one variable each. F_LINE=awk '/<ProfessionalClaim/' test.xml | head -1 L_LINE=awk '/<ProfessionalClaim/' test.xml | tail -1

    – Velava Shanmugam
    Jan 22 at 2:40











  • Thanks! Its done. I have updated the question

    – Velava Shanmugam
    Jan 22 at 17:25
















Hello Velava Shanmugam. It seems there are two issues here: (1) you need to parse and process the file to get the values for the comment, (2) you need to add the comment to the file. What have you tried so far?

– roaima
Jan 21 at 20:00






Hello Velava Shanmugam. It seems there are two issues here: (1) you need to parse and process the file to get the values for the comment, (2) you need to add the comment to the file. What have you tried so far?

– roaima
Jan 21 at 20:00














I have just captured the first and last line that matches the string "<ProfessionalClaim " and stored them in to one variable each. F_LINE=awk '/<ProfessionalClaim/' test.xml | head -1 L_LINE=awk '/<ProfessionalClaim/' test.xml | tail -1

– Velava Shanmugam
Jan 22 at 2:40





I have just captured the first and last line that matches the string "<ProfessionalClaim " and stored them in to one variable each. F_LINE=awk '/<ProfessionalClaim/' test.xml | head -1 L_LINE=awk '/<ProfessionalClaim/' test.xml | tail -1

– Velava Shanmugam
Jan 22 at 2:40













Thanks! Its done. I have updated the question

– Velava Shanmugam
Jan 22 at 17:25





Thanks! Its done. I have updated the question

– Velava Shanmugam
Jan 22 at 17:25










1 Answer
1






active

oldest

votes


















0














Using an XML parser you can extract the necessary components one at a time like this. Let's assume your file is x.xml.



# Parse the XML file for the relevant entries
#
minClaimStartDate=$(xmlstarlet sel -t -v '//_:ProfessionalClaim/@claimStartDate' -n x.xml | sort -V | head -n1)
maxClaimEndDate=$(xmlstarlet sel -t -v '//_:ProfessionalClaim/@claimStartDate' -n x.xml | sort -V | tail -n1)
...

# Grab the XML declaration header
#
header=$(head -n1 x.xml) # Ugh, I can't find a way to do this properly


And then you can put the pieces back together like this



# Output composite
#
echo "$header"
echo "<!-- Claims Paid_Start_Date="$minClaimStartDate" Paid_End_Date="$maxClaimEndDate" ... -->"
xmlstarlet fo --omit-decl x.xml





share|improve this answer























  • xmlstarlet - is this a variable? I am getting error not found.

    – Velava Shanmugam
    Jan 23 at 18:59











  • It's a program. If you're going to parse XML then use an XML parser.

    – roaima
    Jan 23 at 19:05











  • Looks like it is not there. Getting "Command not found error"

    – Velava Shanmugam
    Jan 23 at 19:09











  • You could install it. Or ask your system administration team to do that for you.

    – roaima
    Jan 23 at 19:43











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495844%2fadding-comment-tag-on-xml-file-through-unix%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Using an XML parser you can extract the necessary components one at a time like this. Let's assume your file is x.xml.



# Parse the XML file for the relevant entries
#
minClaimStartDate=$(xmlstarlet sel -t -v '//_:ProfessionalClaim/@claimStartDate' -n x.xml | sort -V | head -n1)
maxClaimEndDate=$(xmlstarlet sel -t -v '//_:ProfessionalClaim/@claimStartDate' -n x.xml | sort -V | tail -n1)
...

# Grab the XML declaration header
#
header=$(head -n1 x.xml) # Ugh, I can't find a way to do this properly


And then you can put the pieces back together like this



# Output composite
#
echo "$header"
echo "<!-- Claims Paid_Start_Date="$minClaimStartDate" Paid_End_Date="$maxClaimEndDate" ... -->"
xmlstarlet fo --omit-decl x.xml





share|improve this answer























  • xmlstarlet - is this a variable? I am getting error not found.

    – Velava Shanmugam
    Jan 23 at 18:59











  • It's a program. If you're going to parse XML then use an XML parser.

    – roaima
    Jan 23 at 19:05











  • Looks like it is not there. Getting "Command not found error"

    – Velava Shanmugam
    Jan 23 at 19:09











  • You could install it. Or ask your system administration team to do that for you.

    – roaima
    Jan 23 at 19:43
















0














Using an XML parser you can extract the necessary components one at a time like this. Let's assume your file is x.xml.



# Parse the XML file for the relevant entries
#
minClaimStartDate=$(xmlstarlet sel -t -v '//_:ProfessionalClaim/@claimStartDate' -n x.xml | sort -V | head -n1)
maxClaimEndDate=$(xmlstarlet sel -t -v '//_:ProfessionalClaim/@claimStartDate' -n x.xml | sort -V | tail -n1)
...

# Grab the XML declaration header
#
header=$(head -n1 x.xml) # Ugh, I can't find a way to do this properly


And then you can put the pieces back together like this



# Output composite
#
echo "$header"
echo "<!-- Claims Paid_Start_Date="$minClaimStartDate" Paid_End_Date="$maxClaimEndDate" ... -->"
xmlstarlet fo --omit-decl x.xml





share|improve this answer























  • xmlstarlet - is this a variable? I am getting error not found.

    – Velava Shanmugam
    Jan 23 at 18:59











  • It's a program. If you're going to parse XML then use an XML parser.

    – roaima
    Jan 23 at 19:05











  • Looks like it is not there. Getting "Command not found error"

    – Velava Shanmugam
    Jan 23 at 19:09











  • You could install it. Or ask your system administration team to do that for you.

    – roaima
    Jan 23 at 19:43














0












0








0







Using an XML parser you can extract the necessary components one at a time like this. Let's assume your file is x.xml.



# Parse the XML file for the relevant entries
#
minClaimStartDate=$(xmlstarlet sel -t -v '//_:ProfessionalClaim/@claimStartDate' -n x.xml | sort -V | head -n1)
maxClaimEndDate=$(xmlstarlet sel -t -v '//_:ProfessionalClaim/@claimStartDate' -n x.xml | sort -V | tail -n1)
...

# Grab the XML declaration header
#
header=$(head -n1 x.xml) # Ugh, I can't find a way to do this properly


And then you can put the pieces back together like this



# Output composite
#
echo "$header"
echo "<!-- Claims Paid_Start_Date="$minClaimStartDate" Paid_End_Date="$maxClaimEndDate" ... -->"
xmlstarlet fo --omit-decl x.xml





share|improve this answer













Using an XML parser you can extract the necessary components one at a time like this. Let's assume your file is x.xml.



# Parse the XML file for the relevant entries
#
minClaimStartDate=$(xmlstarlet sel -t -v '//_:ProfessionalClaim/@claimStartDate' -n x.xml | sort -V | head -n1)
maxClaimEndDate=$(xmlstarlet sel -t -v '//_:ProfessionalClaim/@claimStartDate' -n x.xml | sort -V | tail -n1)
...

# Grab the XML declaration header
#
header=$(head -n1 x.xml) # Ugh, I can't find a way to do this properly


And then you can put the pieces back together like this



# Output composite
#
echo "$header"
echo "<!-- Claims Paid_Start_Date="$minClaimStartDate" Paid_End_Date="$maxClaimEndDate" ... -->"
xmlstarlet fo --omit-decl x.xml






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 22 at 18:11









roaimaroaima

44.6k555119




44.6k555119












  • xmlstarlet - is this a variable? I am getting error not found.

    – Velava Shanmugam
    Jan 23 at 18:59











  • It's a program. If you're going to parse XML then use an XML parser.

    – roaima
    Jan 23 at 19:05











  • Looks like it is not there. Getting "Command not found error"

    – Velava Shanmugam
    Jan 23 at 19:09











  • You could install it. Or ask your system administration team to do that for you.

    – roaima
    Jan 23 at 19:43


















  • xmlstarlet - is this a variable? I am getting error not found.

    – Velava Shanmugam
    Jan 23 at 18:59











  • It's a program. If you're going to parse XML then use an XML parser.

    – roaima
    Jan 23 at 19:05











  • Looks like it is not there. Getting "Command not found error"

    – Velava Shanmugam
    Jan 23 at 19:09











  • You could install it. Or ask your system administration team to do that for you.

    – roaima
    Jan 23 at 19:43

















xmlstarlet - is this a variable? I am getting error not found.

– Velava Shanmugam
Jan 23 at 18:59





xmlstarlet - is this a variable? I am getting error not found.

– Velava Shanmugam
Jan 23 at 18:59













It's a program. If you're going to parse XML then use an XML parser.

– roaima
Jan 23 at 19:05





It's a program. If you're going to parse XML then use an XML parser.

– roaima
Jan 23 at 19:05













Looks like it is not there. Getting "Command not found error"

– Velava Shanmugam
Jan 23 at 19:09





Looks like it is not there. Getting "Command not found error"

– Velava Shanmugam
Jan 23 at 19:09













You could install it. Or ask your system administration team to do that for you.

– roaima
Jan 23 at 19:43






You could install it. Or ask your system administration team to do that for you.

– roaima
Jan 23 at 19:43


















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495844%2fadding-comment-tag-on-xml-file-through-unix%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)