title: Using touch and sed within a find -ok command
body: <p>I have some wav files. For each of those files I would like to create a new text file with the same name (obviously with the <em>wav</em> extension being replaced with <em>txt</em>).  </p>
  
  <p>I first tried this:</p>
  
  <pre><code>find . -name *.wav -exec 'touch $(echo '{}" | sed -r 's/[^.]+\$/txt/')" \;
  </code></pre>
  
  <p>which outputted </p>
  
  <blockquote>
    <p>&lt; touch $(echo {} | sed -r 's/[^.]+$/txt/') ... ./The_stranglers-Golden_brown.wav > ?</p>
  </blockquote>
  
  <p>Then <em>find</em> complained after I hit <em>y</em> key with:  </p>
  
  <blockquote>
    <p>find: ‘touch $(echo ./music.wav | sed -r 's/[^.]+$/txt/')’: No such file or directory</p>
  </blockquote>
  
  <p>I figured out I was using a pipe and actually needed a shell. I then ran:  </p>
  
  <pre><code>find . -name *.wav -exec sh -c 'touch $(echo "'{}"\" | sed -r 's/[^.]+\$/txt/')" \;
  </code></pre>
  
  <p>Which did the job.</p>
  
  <p>Actually, I do not really get what is being done internally, but I guess a shell is spawned on every file right ? I fear this is memory costly.<br>
  Then, what if I need to run this command on a large bunch of files and directories !?</p>
  
  <p>Now is there a way to do this in a more efficient way ?<br>
  Basically I need to transform the current file's name and to feed touch command.</p>
  
  <p>Thank you.</p>