Modify xml in multiple files

Asked

Viewed 981 times

1

Hello,

Personal need to modify a value within an xml Node, the problem is that I need to do this in 1300 files at once, the value I look for inside the node can be any one, it does not make any difference the value that this there, I just need to modify this node in all the files at once, example:

Em um xml pode estar
    <VDesc>9.32</vDesc>
Em outro
    <VDesc>1.45</vDesc>

Em assim por diante.

Preciso modificar em todos arquivos para
    <VDesc>0.00</vDesc>

Just this, some suggestion, what a tool to use?

  • <VDesc> appears more than once in the file or only in the line that should be changed?

  • The tool that will import these files is own or third party?

  • it’s supposed to be like that, <VDesc> and </vDesc>, V and v?

2 answers

2


based on all the answers I managed to solve the problem in a simple and very effective way, I did the following:

With the Notepad ++

Option: "Locate->Replace, Flap Find in files", in the field Locate placed:

<vICMSDeson>(\s*\d+\.\d+\s*)<\/vICMSDeson>

, and in the field Replace with, placed:

<vICMSDeson>0.00</vICMSDeson>

, in Filters put: *.xml to search only in xml files, then in Briefcase I have indicated the path of the xml files, in Search mode I selected "Regular expression". Perfect.

Might be useful to someone else.

Thank you all

0

If you can use perl, here’s a suggestion:

perl -i -pe 's!<VDesc>.*?</VDesc>!<VDesc>0.00</VDesc>!s' *.xml

If you prefer to create a backup of the original (a. xml , a.xml.Bak):

perl -i.bak -pe 's!<VDesc>.*?</VDesc>!<VDesc>0.00</VDesc>!s' *.xml

(I assumed that V, v is V)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.