1

I works on project in bash and i uses in some XML files to get my data.

I takes some tags from the XML file and i order them at one line-

For Example:

I have the tags

ItemName, ItemCode,ItemPrice for every item, e.g Coca-Cola item -

<ItemCode>7290011018931</ItemCode>

  <ItemType>1</ItemType>
  <ItemName>Coca Cole</ItemName>
  <ManufacturerName>some-company.. </ManufacturerName>
  <ManufactureCountry>DE</ManufactureCountry>
  
  <bIsWeighted>0</bIsWeighted>
  <UnitOfMeasure>100 ml</UnitOfMeasure>
  <QtyInPackage>0</QtyInPackage>
  <ItemPrice>4.80</ItemPrice>
  <UnitOfMeasurePrice>1.92</UnitOfMeasurePrice>
  <AllowDiscount>1</AllowDiscount>
  <ItemStatus>0</ItemStatus>`

The program is work but very slowly (it taks for 5000 lines file at least 1.5 minutes to manufacture the new file)-

Most of the operstion are cut and order the file by :

cat ${xmlFile} | grep "ItemCode" | cut -d">" -f2 | cut -d"<" -f1 >Code1.txt

My question is if there is another way to improve that performance and if there is a command at bash that i need to use cerfully when i look for faster solution

Edit

code1.txt is list of Barcodes, i have 2 more files name1.txt and price1.txt and i comained them to one file by that code:

i=0
    while (( i < numOfIterates )); do 
        let i++;
        a=`head -n+${i} Name1.txt | tail -n+${i}`;
        b=`head -n+${i} price1.txt| tail -n+${i}`;
        c=`head -n+${i} code1.txt| tail -n+${i}`;
        echo "$a" "$b" "$c";
    done > Total-${FileName}.txt

When Total-${FileName}.txt is the file in the format:

Name Price Barcode

Community
  • 1
  • 1
Bizzu
  • 449
  • 3
  • 17
  • Perhaps using specialized utility for XML parsing is an option? https://stackoverflow.com/a/894317/7034621 – orhtej2 Oct 07 '17 at 20:49
  • @orhtej2 if i will not find another solution that will be my way, but i want to understand if there is a way to improve my program performance with bash commands – Bizzu Oct 07 '17 at 20:55
  • 1
    @Bizzu, yes, your approach can be improved, show how should look the final `Code1.txt` – RomanPerekhrest Oct 07 '17 at 21:21
  • @RomanPerekhrest Code1.txt will need to look like list of codes which order line by line. i have 2 more files - price.txt and name.txt, and in the end i combains the 3 to one that every line consists name, barcode and price – Bizzu Oct 07 '17 at 21:25
  • @RomanPerekhrest Thanks on your comment, i explained little bit more about the files at the post – Bizzu Oct 07 '17 at 21:34
  • I still see some unclear moments. If you could share the input xml file for me and the expected txt file - I could help – RomanPerekhrest Oct 07 '17 at 21:39

0 Answers0