title: perl or sed command to find 2 strings and replace the first string with string 2
body: <p>I have multiple files with below text.</p>
  
  <p>Content of File 1:</p>
  
  <pre><code>Begin("tmp1","derived from file \"/disks/setup/ORIG_FILE1.txt\"");
  </code></pre>
  
  <p>Content of File 2:</p>
  
  <pre><code>Begin("tmp1","derived from file \"/disks/setup/ORIG_FILE2.txt\"");
  </code></pre>
  
  <p>Content of File 3:</p>
  
  <pre><code>Begin("tmp9","derived from file \"/disks/setup/ORIG_FILE4.txt\"");
  </code></pre>
  
  <p>and so on.....</p>
  
  <p>Is there any command in perl or sed to find a line with "Begin" and in that line search from the first string between "..." (i.e. "tmp1" in our case) and store it in a variable then search for the last string between /..\"" i.e. (ORIG_FILE1.txt here) and store it in the variable 2 and then remove ".txt" from the variable 2 and then replace variable 1 with variable 2 and update the file.</p>
  
  <p>So output files will look like:</p>
  
  <p>Content of File 1:</p>
  
  <pre><code>Begin("ORIG_FILE1","derived from file \"/disks/setup/ORIG_FILE1.txt\"");
  </code></pre>
  
  <p>Content of File 2:</p>
  
  <pre><code>Begin("ORIG_FILE2","derived from file \"/disks/setup/ORIG_FILE2.txt\"");
  </code></pre>
  
  <p>Content of File 3:</p>
  
  <pre><code>Begin("ORIG_FILE4","derived from file \"/disks/setup/ORIG_FILE4.txt\"");
  </code></pre>
  
  <p>and so on.....</p>
  
  <p>Can somebody please help me here?</p>