title: Modify text file based on file's name, repeat for all files in folder
body: <p>I have a folder with several files named : something_1001.txt; something_1002.txt; something_1003.txt; etc.
  Inside the files there is some text. Of course each file has a different text but the structure is always the same: some lines identified with the string ">TEXT", which are the ones I am interested in.</p>
  
  <p>So my goal is :</p>
  
  <ul>
  <li>for each file in the folder, read the file's name and extract the number between "_" and ".txt"</li>
  <li>modify all the lines in this particular file that contain the string ">TEXT" in order to make it ">{NUMBER}_TEXT"</li>
  <li>For example : file "something_1001.txt"; change all the lines containing ">TEXT" by ">1001_TEXT"; move on to file "something_1002.txt" change all the lines containing ">TEXT" by ">1002_TEXT"; etc.</li>
  </ul>
  
  <p>Here is the code I wrote so far :</p>
  
  <pre><code>for i in /folder/*.txt
  NAME=`echo $i | grep -oP '(?&lt;=something_/).*(?=\.txt)'`
  do  
      sed -i -e 's/&gt;TEXT/&gt;${NAME}_TEXT/g' /folder/something_${NAME}.txt
  done
  </code></pre>
  
  <p>I created a small bash script to run the code but it's not working. There seems to be syntax errors and a loop error, but I can't figure out where.</p>
  
  <p>Any help would be most welcome !</p>