Rename a particular instance in multiple files with the file name?
<p>I had to create about 500 copies of a xml file in the directory, which I managed to get done. As a part of the next problem is that I want to rename particular text in the file. How can I go about doing it?</p>

<p>This is what I have:
1000.xml, 1001.xml, 1002.xml...</p>

<p>1000.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;addresses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation='test.xsd'&gt;
&lt;address&gt;
    &lt;name&gt;Joe Tester&lt;/name&gt;
    &lt;street&gt;Baker street 5&lt;/street&gt;
    &lt;id&gt;1000&lt;/id&gt;
&lt;/address&gt;
&lt;count&gt;1000&lt;/count&gt;
</code></pre>

<p></p>

<p>Essentially, this is copied to all the other files, but with a numerical and chronological name. How do I replace this "1000" with the "file name"? So, the new file should be -
1001.xml:</p>

<pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;addresses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:noNamespaceSchemaLocation='test.xsd'&gt;
    &lt;address&gt;
        &lt;name&gt;Joe Tester&lt;/name&gt;
        &lt;street&gt;Baker street 5&lt;/street&gt;
        &lt;id&gt;1001&lt;/id&gt;
    &lt;/address&gt;
    &lt;count&gt;1001&lt;/count&gt;
&lt;/addresses&gt;
</code></pre>

<p>I could do only this - <code>sed -i '' -e 's/1000/1001/g' $(find . -type f)</code> which will replace all the 1000 with 1001, but not the file name.</p>

<p>Try your sed command in a loop-</p>

<pre><code>for i in {1000..1500} #or whatever your maximum number is
do
sed -i "s/1000/"$i"/g" "$i".xml
done
</code></pre>

python bash perl