I have around 4000 XML files and I need to replace the value of both <filename> and <path> fields.
I need to replace those fields dynamically. e.g. images0001.xml should have images0001 inside the two fields, images0002.xml should have images0002 inside the two fields, etc.
I've already used this command to rename the files sequentially:
rename 's/.+/our $i; sprintf("images%04d.jpg", 1+$i++)/e' *
And I also used this command to delete the .jpg extension that was in the two fields I'm trying to change:
sed -i 's/.jpg//g' Annotations/*
Here is the current state of the contents of the XML files:
<annotation>
<folder></folder>
<filename>1608644703_2.rf.fa179c1e6c47d72d668ac3d83c7f79d1</filename>
<path>1608644703_2.rf.fa179c1e6c47d72d668ac3d83c7f79d1</path>
<source>
<database>roboflow.ai</database>
</source>
<size>
<width>416</width>
<height>416</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>megot</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<occluded>0</occluded>
<bndbox>
<xmin>129</xmin>
<xmax>292</xmax>
<ymin>145</ymin>
<ymax>351</ymax>
</bndbox>
</object>
</annotation>
And here is how I need the files to be changed:
<annotation>
<folder></folder>
<filename>images0001</filename>
<path>images0001</path>
<source>
<database>roboflow.ai</database>
</source>
<size>
<width>416</width>
<height>416</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>megot</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<occluded>0</occluded>
<bndbox>
<xmin>129</xmin>
<xmax>292</xmax>
<ymin>145</ymin>
<ymax>351</ymax>
</bndbox>
</object>
</annotation>
I'm looking for a way to do this in command line, but I can't figure out a solution after searching for a while!
Any help will be appreciate. Thanks in advance!