Deleting lines on matching certain pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting lines on matching certain pattern
# 1  
Old 05-22-2015
Deleting lines on matching certain pattern

hi

I have a large xml file from which i have taken few lines . In this file I have to find for the string </invoices> and check if the 3 rd line after this string does not begin with <portCode> ,then i have to delete the string </invoices> and the next line having the string </shippingBill> . In other words if the 3rd line after the string begins with <invoiceSerialNo> then i have to delete the string </invoices> and the next line having the string </shippingBill>

Thanks in anticipation


Code:
   <shippingBill> 
      <portCode>INAJJ6</portCode> 
      <exportType>1</exportType> 
      <recordIndicator>1</recordIndicator> 
      <shippingBillNo>6574340</shippingBillNo> 
      <shippingBillDate>11/12/2014</shippingBillDate> 
      <formNo></formNo> 
      <LEODate>11/12/2014</LEODate> 
      <adCode>0240345</adCode> 
      <ebrcNumber>M96EXCU143630003</ebrcNumber> 
   <invoices> 
    <invoice> 
        <invoiceSerialNo>1</invoiceSerialNo> 
        <invoiceNo>ICCEXP14-15RP/189</invoiceNo> 
        <invoiceDate></invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>EUR</realizedCurrencyCode> 
        <realizationDate>07/05/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>90</bankingChargesAmt> 
        <FOBAmt>29807.68</FOBAmt> 
        <FOBAmtIC>29717.68</FOBAmtIC> 
        <freightAmt>131733</freightAmt> 
        <freightAmtIC>131733</freightAmtIC> 
        <insuranceAmt>279</insuranceAmt> 
        <insuranceAmtIC>279</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>1</closeOfBillIndicator> 
        <remitterName>SOLIDARIDAD Y TRABAJO</remitterName> 
        <remitterCountry>ES</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
   <shippingBill> 
      <portCode>INDIG6</portCode> 
      <exportType>1</exportType> 
      <recordIndicator>1</recordIndicator> 
      <shippingBillNo>7627181</shippingBillNo> 
      <shippingBillDate>05/02/2015</shippingBillDate> 
      <formNo></formNo> 
      <LEODate>05/02/2015</LEODate> 
      <adCode>0242412</adCode> 
      <ebrcNumber>N41EXCU150730003</ebrcNumber> 
   <invoices> 
    <invoice> 
        <invoiceSerialNo>1</invoiceSerialNo> 
        <invoiceNo>2015EUEX000000043</invoiceNo> 
        <invoiceDate></invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>23/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>25</bankingChargesAmt> 
        <FOBAmt>11551.68</FOBAmt> 
        <FOBAmtIC>11526.68</FOBAmtIC> 
        <freightAmt>573.95</freightAmt> 
        <freightAmtIC>573.95</freightAmtIC> 
        <insuranceAmt>3.63</insuranceAmt> 
        <insuranceAmtIC>3.63</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>CONCENTRIC ITASCA INC</remitterName> 
        <remitterCountry>US</remitterCountry> 
       </invoice> 
    <invoice> 
        <invoiceSerialNo>3066846</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/364/14-15</invoiceNo> 
        <invoiceDate>02/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>1292.15</FOBAmt> 
        <FOBAmtIC>1292.15</FOBAmtIC> 
        <freightAmt>10</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>1</insuranceAmt> 
        <insuranceAmtIC>1</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
    <invoice> 
        <invoiceSerialNo>3066850</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/365/14-15</invoiceNo> 
        <invoiceDate>02/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>371.1</FOBAmt> 
        <FOBAmtIC>371.1</FOBAmtIC> 
        <freightAmt>3</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>1</insuranceAmt> 
        <insuranceAmtIC>1</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
    <invoice> 
        <invoiceSerialNo>3066854</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/366/14-15</invoiceNo> 
        <invoiceDate>02/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>13725.6</FOBAmt> 
        <FOBAmtIC>13725.6</FOBAmtIC> 
        <freightAmt>101</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>15</insuranceAmt> 
        <insuranceAmtIC>15</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
    <invoice> 
        <invoiceSerialNo>3066864</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/367/14-15</invoiceNo> 
        <invoiceDate>02/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>6448.57</FOBAmt> 
        <FOBAmtIC>6448.57</FOBAmtIC> 
        <freightAmt>48</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>7</insuranceAmt> 
        <insuranceAmtIC>7</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
    <invoice> 
        <invoiceSerialNo>3066878</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/368/14-15</invoiceNo> 
        <invoiceDate>02/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>5169.58</FOBAmt> 
        <FOBAmtIC>5169.58</FOBAmtIC> 
        <freightAmt>38</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>6</insuranceAmt> 
        <insuranceAmtIC>6</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
    <invoice> 
        <invoiceSerialNo>2542605</invoiceSerialNo> 
        <invoiceNo>O-025</invoiceNo> 
        <invoiceDate>03/07/2014</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>27/11/2014</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>504.12</bankingChargesAmt> 
        <FOBAmt>10020</FOBAmt> 
        <FOBAmtIC>10020</FOBAmtIC> 
        <freightAmt>0</freightAmt> 
        <freightAmtIC>0</freightAmtIC> 
        <insuranceAmt>0</insuranceAmt> 
        <insuranceAmtIC>0</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt></discountAmt> 
        <discountAmtIC></discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>LEE AND SOH TRADING COMPANY</remitterName> 
        <remitterCountry>BN</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
   <shippingBill> 
      <portCode>INFLT6</portCode> 
      <exportType>1</exportType> 
      <recordIndicator>1</recordIndicator> 
      <shippingBillNo>0000359</shippingBillNo> 
      <shippingBillDate>02/02/2015</shippingBillDate> 
      <formNo>G15000460701</formNo> 
      <LEODate>02/02/2015</LEODate> 
      <adCode>0242081</adCode> 
      <ebrcNumber>H53EBOU150480008</ebrcNumber> 
   <invoices> 
    <invoice> 
        <invoiceSerialNo>3156545</invoiceSerialNo> 
        <invoiceNo>F15152</invoiceNo> 
        <invoiceDate>31/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>EUR</realizedCurrencyCode> 
        <realizationDate>20/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>2303.43</FOBAmt> 
        <FOBAmtIC>2303.43</FOBAmtIC> 
        <freightAmt>3000</freightAmt> 
        <freightAmtIC>3000</freightAmtIC> 
        <insuranceAmt>115</insuranceAmt> 
        <insuranceAmtIC>115</insuranceAmtIC> 
        <commissionAmt>234.91</commissionAmt> 
        <commissionAmtIC>234.91</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>1</closeOfBillIndicator> 
        <remitterName>ALTEA S R L</remitterName> 
        <remitterCountry>IT</remitterCountry> 
       </invoice> 
    <invoice> 
        <invoiceSerialNo>3085228</invoiceSerialNo> 
        <invoiceNo>EX-082/14-15</invoiceNo> 
        <invoiceDate>08/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>23/01/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>131115</FOBAmt> 
        <FOBAmtIC>131115</FOBAmtIC> 
        <freightAmt>345.85</freightAmt> 
        <freightAmtIC>345.85</freightAmtIC> 
        <insuranceAmt>59.15</insuranceAmt> 
        <insuranceAmtIC>59.15</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>ALBREKTS GULD</remitterName> 
        <remitterCountry>SE</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
   <shippingBill> 
      <portCode>INNDA6</portCode> 
      <exportType>1</exportType> 
      <recordIndicator>1</recordIndicator> 
      <shippingBillNo>0000405</shippingBillNo> 
      <shippingBillDate>08/01/2015</shippingBillDate> 
      <formNo>G15000421178</formNo> 
      <LEODate>09/01/2015</LEODate> 
      <adCode>0242327</adCode> 
      <ebrcNumber>M01EBFA150840020</ebrcNumber> 
   <invoices> 
    <invoice> 
        <invoiceSerialNo>3087662</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/373/14-15</invoiceNo> 
        <invoiceDate>08/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>522.35</FOBAmt> 
        <FOBAmtIC>522.35</FOBAmtIC> 
        <freightAmt>4</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>1</insuranceAmt> 
        <insuranceAmtIC>1</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
    <invoice> 
        <invoiceSerialNo>3087672</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/374/14-15</invoiceNo> 
        <invoiceDate>08/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>20002.24</FOBAmt> 
        <FOBAmtIC>20002.24</FOBAmtIC> 
        <freightAmt>141</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>21</insuranceAmt> 
        <insuranceAmtIC>21</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
    <invoice> 
        <invoiceSerialNo>3087674</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/375/14-15</invoiceNo> 
        <invoiceDate>08/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>7742.45</FOBAmt> 
        <FOBAmtIC>7742.45</FOBAmtIC> 
        <freightAmt>55</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>8</insuranceAmt> 
        <insuranceAmtIC>8</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill>
<shippingBill> 
      <portCode>INDIG6</portCode> 
      <exportType>1</exportType> 
      <recordIndicator>1</recordIndicator> 
      <shippingBillNo>7627181</shippingBillNo> 
      <shippingBillDate>05/02/2015</shippingBillDate> 
      <formNo></formNo> 
      <LEODate>05/02/2015</LEODate> 
      <adCode>0242412</adCode> 
      <ebrcNumber>N41EXCU150730003</ebrcNumber> 
   <invoices> 
    <invoice> 
        <invoiceSerialNo>1</invoiceSerialNo> 
        <invoiceNo>2015EUEX000000043</invoiceNo> 
        <invoiceDate></invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>23/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>25</bankingChargesAmt> 
        <FOBAmt>11551.68</FOBAmt> 
        <FOBAmtIC>11526.68</FOBAmtIC> 
        <freightAmt>573.95</freightAmt> 
        <freightAmtIC>573.95</freightAmtIC> 
        <insuranceAmt>3.63</insuranceAmt> 
        <insuranceAmtIC>3.63</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>CONCENTRIC ITASCA INC</remitterName> 
        <remitterCountry>US</remitterCountry> 
       </invoice> 
    <invoice> 
        <invoiceSerialNo>3066846</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/364/14-15</invoiceNo> 
        <invoiceDate>02/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>1292.15</FOBAmt> 
        <FOBAmtIC>1292.15</FOBAmtIC> 
        <freightAmt>10</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>1</insuranceAmt> 
        <insuranceAmtIC>1</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
    <invoice> 
        <invoiceSerialNo>3066850</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/365/14-15</invoiceNo> 
        <invoiceDate>02/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>371.1</FOBAmt> 
        <FOBAmtIC>371.1</FOBAmtIC> 
        <freightAmt>3</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>1</insuranceAmt> 
        <insuranceAmtIC>1</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
    <invoice> 
        <invoiceSerialNo>3066854</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/366/14-15</invoiceNo> 
        <invoiceDate>02/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>13725.6</FOBAmt> 
        <FOBAmtIC>13725.6</FOBAmtIC> 
        <freightAmt>101</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>15</insuranceAmt> 
        <insuranceAmtIC>15</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
    <invoice> 
        <invoiceSerialNo>3066864</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/367/14-15</invoiceNo> 
        <invoiceDate>02/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>6448.57</FOBAmt> 
        <FOBAmtIC>6448.57</FOBAmtIC> 
        <freightAmt>48</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>7</insuranceAmt> 
        <insuranceAmtIC>7</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
    <invoice> 
        <invoiceSerialNo>3066878</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/368/14-15</invoiceNo> 
        <invoiceDate>02/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>5169.58</FOBAmt> 
        <FOBAmtIC>5169.58</FOBAmtIC> 
        <freightAmt>38</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>6</insuranceAmt> 
        <insuranceAmtIC>6</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
    <invoice> 
        <invoiceSerialNo>2542605</invoiceSerialNo> 
        <invoiceNo>O-025</invoiceNo> 
        <invoiceDate>03/07/2014</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>27/11/2014</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>504.12</bankingChargesAmt> 
        <FOBAmt>10020</FOBAmt> 
        <FOBAmtIC>10020</FOBAmtIC> 
        <freightAmt>0</freightAmt> 
        <freightAmtIC>0</freightAmtIC> 
        <insuranceAmt>0</insuranceAmt> 
        <insuranceAmtIC>0</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt></discountAmt> 
        <discountAmtIC></discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>LEE AND SOH TRADING COMPANY</remitterName> 
        <remitterCountry>BN</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
   <shippingBill> 
      <portCode>INFLT6</portCode> 
      <exportType>1</exportType> 
      <recordIndicator>1</recordIndicator> 
      <shippingBillNo>0000359</shippingBillNo> 
      <shippingBillDate>02/02/2015</shippingBillDate> 
      <formNo>G15000460701</formNo> 
      <LEODate>02/02/2015</LEODate> 
      <adCode>0242081</adCode> 
      <ebrcNumber>H53EBOU150480008</ebrcNumber> 
   <invoices> 
    <invoice> 
        <invoiceSerialNo>3156545</invoiceSerialNo> 
        <invoiceNo>F15152</invoiceNo> 
        <invoiceDate>31/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>EUR</realizedCurrencyCode> 
        <realizationDate>20/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>2303.43</FOBAmt> 
        <FOBAmtIC>2303.43</FOBAmtIC> 
        <freightAmt>3000</freightAmt> 
        <freightAmtIC>3000</freightAmtIC> 
        <insuranceAmt>115</insuranceAmt> 
        <insuranceAmtIC>115</insuranceAmtIC> 
        <commissionAmt>234.91</commissionAmt> 
        <commissionAmtIC>234.91</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>1</closeOfBillIndicator> 
        <remitterName>ALTEA S R L</remitterName> 
        <remitterCountry>IT</remitterCountry> 
       </invoice> 
    <invoice> 
        <invoiceSerialNo>3085228</invoiceSerialNo> 
        <invoiceNo>EX-082/14-15</invoiceNo> 
        <invoiceDate>08/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>23/01/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>131115</FOBAmt> 
        <FOBAmtIC>131115</FOBAmtIC> 
        <freightAmt>345.85</freightAmt> 
        <freightAmtIC>345.85</freightAmtIC> 
        <insuranceAmt>59.15</insuranceAmt> 
        <insuranceAmtIC>59.15</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>ALBREKTS GULD</remitterName> 
        <remitterCountry>SE</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
   <shippingBill> 
      <portCode>INNDA6</portCode> 
      <exportType>1</exportType> 
      <recordIndicator>1</recordIndicator> 
      <shippingBillNo>0000405</shippingBillNo> 
      <shippingBillDate>08/01/2015</shippingBillDate> 
      <formNo>G15000421178</formNo> 
      <LEODate>09/01/2015</LEODate> 
      <adCode>0242327</adCode> 
      <ebrcNumber>M01EBFA150840020</ebrcNumber> 
   <invoices> 
    <invoice> 
        <invoiceSerialNo>3087662</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/373/14-15</invoiceNo> 
        <invoiceDate>08/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>522.35</FOBAmt> 
        <FOBAmtIC>522.35</FOBAmtIC> 
        <freightAmt>4</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>1</insuranceAmt> 
        <insuranceAmtIC>1</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
    <invoice> 
        <invoiceSerialNo>3087672</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/374/14-15</invoiceNo> 
        <invoiceDate>08/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>20002.24</FOBAmt> 
        <FOBAmtIC>20002.24</FOBAmtIC> 
        <freightAmt>141</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>21</insuranceAmt> 
        <insuranceAmtIC>21</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill> 
    <invoice> 
        <invoiceSerialNo>3087674</invoiceSerialNo> 
        <invoiceNo>DC-G/NSEZ/375/14-15</invoiceNo> 
        <invoiceDate>08/01/2015</invoiceDate> 
        <realizationStatus>2</realizationStatus> 
        <FIRCNumber></FIRCNumber> 
        <FIRCADCode></FIRCADCode> 
        <realizedCurrencyCode>USD</realizedCurrencyCode> 
        <realizationDate>24/04/2015</realizationDate> 
        <accountNumber></accountNumber> 
        <bankingChargesAmt>0</bankingChargesAmt> 
        <FOBAmt>7742.45</FOBAmt> 
        <FOBAmtIC>7742.45</FOBAmtIC> 
        <freightAmt>55</freightAmt> 
        <freightAmtIC>200</freightAmtIC> 
        <insuranceAmt>8</insuranceAmt> 
        <insuranceAmtIC>8</insuranceAmtIC> 
        <commissionAmt>0</commissionAmt> 
        <commissionAmtIC>0</commissionAmtIC> 
        <packagingChargesAmt>0</packagingChargesAmt> 
        <packagingChargesAmtIC>0</packagingChargesAmtIC> 
        <deductionAmt>0</deductionAmt> 
        <deductionAmtIC>0</deductionAmtIC> 
        <discountAmt>0</discountAmt> 
        <discountAmtIC>0</discountAmtIC> 
        <closeOfBillIndicator>2</closeOfBillIndicator> 
        <remitterName>HISTOIRE D OR SA</remitterName> 
        <remitterCountry>FR</remitterCountry> 
       </invoice> 
     </invoices> 
   </shippingBill>


Last edited by Don Cragun; 05-22-2015 at 11:40 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 05-22-2015
A shorter example would have been appreciated, and highlighting the lines you wanted removed from your sample XML file would help us clearly understand what you're trying to do...

Do the spaces at the ends of some of your strings have to be matched, or is matching the closing tags in your strings sufficient?

What have you tried to solve this problem?

What operating system are you using?
# 3  
Old 05-23-2015
Hi

What I have done is a i have taken a output of the xml query and generated this xml using a script however in the xml wherever there is more than 2 child i have this problem which i could not resolve

I'm sorry for the large example ,For easier understanding
I have cut a portion of the earlier xml . What i'm looking for is if the 3 rd line after the tag
</invoices> (Only the closing tag which i have made in bold) is

<portCode> then no need to do any action but if it is


<invoiceSerialNo> then i have to delete the line
</invoices> and the next line

</shippingBill>

Code:
<discountAmtIC>0</discountAmtIC>          <closeOfBillIndicator>1</closeOfBillIndicator>          <remitterName>SOLIDARIDAD Y TRABAJO</remitterName>          <remitterCountry>ES</remitterCountry>         </invoice>       </invoices>     </shippingBill>     <shippingBill>        <portCode>INDIG6</portCode>        <exportType>1</exportType>        <recordIndicator>1</recordIndicator>        <shippingBillNo>7627181</shippingBillNo>        <shippingBillDate>05/02/2015</shippingBillDate>        <formNo></formNo>        <LEODate>05/02/2015</LEODate>        <adCode>0242412</adCode>        <ebrcNumber>N41EXCU150730003</ebrcNumber>     <invoices>      <invoice>          <invoiceSerialNo>1</invoiceSerialNo>          <invoiceNo>2015EUEX000000043</invoiceNo>          <invoiceDate></invoiceDate>          <realizationStatus>2</realizationStatus>          <FIRCNumber></FIRCNumber>          <FIRCADCode></FIRCADCode>          <realizedCurrencyCode>USD</realizedCurrencyCode>          <realizationDate>23/04/2015</realizationDate>          <accountNumber></accountNumber>          <bankingChargesAmt>25</bankingChargesAmt>          <FOBAmt>11551.68</FOBAmt>          <FOBAmtIC>11526.68</FOBAmtIC>          <freightAmt>573.95</freightAmt>          <freightAmtIC>573.95</freightAmtIC>          <insuranceAmt>3.63</insuranceAmt>          <insuranceAmtIC>3.63</insuranceAmtIC>          <commissionAmt>0</commissionAmt>          <commissionAmtIC>0</commissionAmtIC>          <packagingChargesAmt>0</packagingChargesAmt>          <packagingChargesAmtIC>0</packagingChargesAmtIC>          <deductionAmt>0</deductionAmt>          <deductionAmtIC>0</deductionAmtIC>          <discountAmt>0</discountAmt>          <discountAmtIC>0</discountAmtIC>          <closeOfBillIndicator>2</closeOfBillIndicator>          <remitterName>CONCENTRIC ITASCA INC</remitterName>          <remitterCountry>US</remitterCountry>         </invoice>      <invoice>          <invoiceSerialNo>3066846</invoiceSerialNo>          <invoiceNo>DC-G/NSEZ/364/14-15</invoiceNo>          <invoiceDate>02/01/2015</invoiceDate>          <realizationStatus>2</realizationStatus>          <FIRCNumber></FIRCNumber>          <FIRCADCode></FIRCADCode>          <realizedCurrencyCode>USD</realizedCurrencyCode>          <realizationDate>24/04/2015</realizationDate>          <accountNumber></accountNumber>          <bankingChargesAmt>0</bankingChargesAmt>          <FOBAmt>1292.15</FOBAmt>          <FOBAmtIC>1292.15</FOBAmtIC>          <freightAmt>10</freightAmt>          <freightAmtIC>200</freightAmtIC>          <insuranceAmt>1</insuranceAmt>          <insuranceAmtIC>1</insuranceAmtIC>          <commissionAmt>0</commissionAmt>          <commissionAmtIC>0</commissionAmtIC>          <packagingChargesAmt>0</packagingChargesAmt>          <packagingChargesAmtIC>0</packagingChargesAmtIC>          <deductionAmt>0</deductionAmt>          <deductionAmtIC>0</deductionAmtIC>          <discountAmt>0</discountAmt>          <discountAmtIC>0</discountAmtIC>          <closeOfBillIndicator>2</closeOfBillIndicator>          <remitterName>HISTOIRE D OR SA</remitterName>          <remitterCountry>FR</remitterCountry>         </invoice>       <discountAmtIC>0</discountAmtIC>          <closeOfBillIndicator>1</closeOfBillIndicator>          <remitterName>SOLIDARIDAD Y TRABAJO</remitterName>          <remitterCountry>ES</remitterCountry>         </invoice>       </invoices>     </shippingBill>     <shippingBill>        <portCode>INDIG6</portCode>        <exportType>1</exportType>        <recordIndicator>1</recordIndicator>        <shippingBillNo>7627181</shippingBillNo>        <shippingBillDate>05/02/2015</shippingBillDate>        <formNo></formNo>        <LEODate>05/02/2015</LEODate>        <adCode>0242412</adCode>        <ebrcNumber>N41EXCU150730003</ebrcNumber>     <invoices>     <invoice>         <invoiceSerialNo>1</invoiceSerialNo>          <invoiceNo>2015EUEX000000043</invoiceNo>          <invoiceDate></invoiceDate>          <realizationStatus>2</realizationStatus>          <FIRCNumber></FIRCNumber>          <FIRCADCode></FIRCADCode>          <realizedCurrencyCode>USD</realizedCurrencyCode>          <realizationDate>23/04/2015</realizationDate>          <accountNumber></accountNumber>          <bankingChargesAmt>25</bankingChargesAmt>          <FOBAmt>11551.68</FOBAmt>          <FOBAmtIC>11526.68</FOBAmtIC>          <freightAmt>573.95</freightAmt>          <freightAmtIC>573.95</freightAmtIC>          <insuranceAmt>3.63</insuranceAmt>          <insuranceAmtIC>3.63</insuranceAmtIC>          <commissionAmt>0</commissionAmt>          <commissionAmtIC>0</commissionAmtIC>          <packagingChargesAmt>0</packagingChargesAmt>          <packagingChargesAmtIC>0</packagingChargesAmtIC>          <deductionAmt>0</deductionAmt>          <deductionAmtIC>0</deductionAmtIC>          <discountAmt>0</discountAmt>          <discountAmtIC>0</discountAmtIC>          <closeOfBillIndicator>2</closeOfBillIndicator>          <remitterName>CONCENTRIC ITASCA INC</remitterName>          <remitterCountry>US</remitterCountry>         </invoice>      <invoice>          <invoiceSerialNo>3066846</invoiceSerialNo>          <invoiceNo>DC-G/NSEZ/364/14-15</invoiceNo>          <invoiceDate>02/01/2015</invoiceDate>          <realizationStatus>2</realizationStatus>          <FIRCNumber></FIRCNumber>          <FIRCADCode></FIRCADCode>          <realizedCurrencyCode>USD</realizedCurrencyCode>          <realizationDate>24/04/2015</realizationDate>          <accountNumber></accountNumber>          <bankingChargesAmt>0</bankingChargesAmt>          <FOBAmt>1292.15</FOBAmt>          <FOBAmtIC>1292.15</FOBAmtIC>          <freightAmt>10</freightAmt>          <freightAmtIC>200</freightAmtIC>          <insuranceAmt>1</insuranceAmt>          <insuranceAmtIC>1</insuranceAmtIC>          <commissionAmt>0</commissionAmt>          <commissionAmtIC>0</commissionAmtIC>          <packagingChargesAmt>0</packagingChargesAmt>          <packagingChargesAmtIC>0</packagingChargesAmtIC>          <deductionAmt>0</deductionAmt>          <deductionAmtIC>0</deductionAmtIC>          <discountAmt>0</discountAmt>          <discountAmtIC>0</discountAmtIC>          <closeOfBillIndicator>2</closeOfBillIndicator>          <remitterName>HISTOIRE D OR SA</remitterName>          <remitterCountry>FR</remitterCountry>         </invoice>       </invoices>     </shippingBill>      <invoice>          <invoiceSerialNo>3066850</invoiceSerialNo>          <invoiceNo>DC-G/NSEZ/365/14-15</invoiceNo>       </shippingBill>      <invoice>          <invoiceSerialNo>3066850</invoiceSerialNo>          <invoiceNo>DC-G/NSEZ/365/14-15</invoiceNo>


Last edited by Don Cragun; 05-23-2015 at 12:47 AM.. Reason: Add CODE tags.
# 4  
Old 05-23-2015
Your refusal to use CODE tags makes it impossible to see the difference between a single space and a sequence of one or more space and tab characters. Please use CODE tags as required by the rules you agreed to when you joined the UNIX & Linux Forums.

Your choice to put an entire XML file on a single line makes the text processing tools available on UNIX-like systems unusable. The standards leave the results unspecified if lines in the files being processed are longer than LINE_MAX bytes (including the terminating <newline> character). On many systems LINE_MAX is 2048.

Your refusal to tell us what operating system you're using, along with a single line XML file, makes coming up with a script that might work for you overly complicated.

And, talking about the 3rd line after something in a file that only contains one line, by definition, means that you don't want anything changed.
# 5  
Old 05-23-2015
Sorry again ,I'll retry
I want to search for the string <invoiceSerialNo> and if the 2nd line and 3rd line above this string is </invoices> and </shippingBill> then delete the 2nd and 3rd lines above the string ( ie delete </invoices> and </shippingBill>) .Thanks again

Code:
<ebrcNumber>N41EXCU150730003</ebrcNumber>
   <invoices>
    <invoice>
        <invoiceSerialNo>1</invoiceSerialNo> 
</invoices>
  </shippingBill>
    <invoice>
        <invoiceSerialNo>3066850</invoiceSerialNo>
</invoices>
   </shippingBill>
    <invoice>
        <invoiceSerialNo>3066854</invoiceSerialNo>
 <ebrcNumber>N41EXCU150030008</ebrcNumber>
   <invoices>
    <invoice>
        <invoiceSerialNo>1</invoiceSerialNo>

# 6  
Old 05-23-2015
So, no attempts from your part?

---------- Post updated at 15:59 ---------- Previous update was at 15:59 ----------

Anyhow, try
Code:
awk '
/<\/invoices>/  {SLINV = $0
                 getline SB
                 getline INV
                 getline
                 if     (/<invoiceSerialNo>/ &&
                         SB ~ /<\/shippingBill>/)       {print SLINV
                                                         print SB   
                                                        }
                 print INV}
1
' file

and comment on the result.
# 7  
Old 05-23-2015
Thanks Rudi

the script is deleting the lines
Code:
</invoices>
   </shippingBill>

,but at the wrong place .In other words it is deleting tags above line starting with
Code:
<portCode>

instead of the line starting with
Code:
<invoiceSerialNo>

As regards my efforts i was trying with a for loop which was not working something like
Code:
#!/usr/bin/sh
for i in `grep -B 2 "<invoiceSerialNo>" `
do
nawk '{gsub (shippingBill,"");print}' test2  >> s
done

Thanks again

Last edited by Don Cragun; 05-23-2015 at 04:33 PM.. Reason: Add CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

2. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

3. Shell Programming and Scripting

Help with a deleting lines based on a pattern

I have a header-detail file that goes like this: SHP00288820131021110921 ORDER0156605920131021110921INMMMMFN DETAIL0004 4C2Z 10769 AAFC 0000009600000094 4C2Z 10769 AAFC 0000672107 OIL DETAIL0002 ER3Z 14300 E 0000001300000012 ER3Z 14300 E 0000672107 OIL... (3 Replies)
Discussion started by: rbaggio666
3 Replies

4. Shell Programming and Scripting

Deleting a matching string(line) which is also in other lines

Hi, i need help with my shell script I have a file input.txt containing the following contents /. /usr /usr/share /usr/share/doc /usr/share/doc/wine /usr/share/doc/wine/copyright /usr/share/doc/wine/changelog.Debian.gz I need output as /usr/share/doc/wine /usr/share/doc/wine/copyright... (3 Replies)
Discussion started by: Amit0991
3 Replies

5. Shell Programming and Scripting

Deleting lines from a stream after matching a pattern

Hi, I have a requirement to to an ldapsearch and remove the shadow attributes in the output file. What I do is ldapsearch() | operation to remove shadow > FILE The ldapsearch gives output like this(with same line formation): objectClass: FSConfig objectClass: extensibleObject fsCAIP:... (10 Replies)
Discussion started by: lorzinian
10 Replies

6. Shell Programming and Scripting

Finding lines matching the Pattern and their previous lines in a file

Hi, I am trying to locate the occurences of certain pattern like 'Possible network disconnect' in a text file. I can get the actual lines matching the pttern using: grep -w 'Possible network disconnect' file_name. But I am more interested in getting the timing of these events which are... (7 Replies)
Discussion started by: sagarparadkar
7 Replies

7. Shell Programming and Scripting

pattern matching lines using the date, and then joining the lines

Hi Guys, Was trying to attempt the below using awk and sed, have no luck so far, so any help would be appreciated. Current Text File: The first line has got an "\n", and the second line has got spaces/tabs then the word and "\n" TIME SERVER/CLIENT TEXT... (6 Replies)
Discussion started by: eo29
6 Replies

8. Shell Programming and Scripting

pattern matching over multiple lines and deleting the first

I've got a longish log file with content such as Uplink traffic: Downlink traffic: I want to parse the log file and remove any line that contains the string "Uplink traffic:" at the beginning of the line, but only if the line following it beginnings with the string "Downlink traffic:" (in... (7 Replies)
Discussion started by: Yorkie99
7 Replies

9. Shell Programming and Scripting

sed: deleting 5 lines after a specified pattern

As an example (just an example, this could apply to any block of text) say I have this: architecture x86_64 cputype CPU_TYPE_X86_64 cpusubtype CPU_SUBTYPE_X86_64_ALL offset 4096 size 2972420 align 2^12 (4096) architecture ppc64 cputype CPU_TYPE_POWERPC64 cpusubtype... (3 Replies)
Discussion started by: pcwiz
3 Replies

10. Shell Programming and Scripting

counting the lines matching a pattern, in between two pattern, and generate a tab

Hi all, I'm looking for some help. I have a file (very long) that is organized like below: >Cluster 0 0 283nt, >01_FRYJ6ZM12HMXZS... at +/99% 1 279nt, >01_FRYJ6ZM12HN12A... at +/99% 2 281nt, >01_FRYJ6ZM12HM4TS... at +/99% 3 283nt, >01_FRYJ6ZM12HM946... at +/99% 4 279nt,... (4 Replies)
Discussion started by: d.chauliac
4 Replies
Login or Register to Ask a Question