title: Modifying replace string in xargs
body: <p>When I am using <code>xargs</code> sometimes I do not need to explicitly use the replacing string:</p>
  
  <pre><code>find . -name "*.txt" | xargs rm -rf
  </code></pre>
  
  <p>In other cases, I want to specify the replacing string in order to do things like:</p>
  
  <pre><code>find . -name "*.txt" | xargs -I '{}' mv '{}' /foo/'{}'.bar
  </code></pre>
  
  <p>The previous command would move all the text files under the current directory into <code>/foo</code> and it will append the extension <code>bar</code> to all the files.</p>
  
  <p>If instead of appending some text to the replace string, I wanted to modify that string such that I could insert some text between the name and extension of the files, how could I do that? For instance, let's say I want to do the same as in the previous example, but the files should be renamed/moved from <code>&lt;name&gt;.txt</code> to <code>/foo/&lt;name&gt;.bar.txt</code> (instead of <code>/foo/&lt;name&gt;.txt.bar</code>).</p>
  
  <p><strong>UPDATE</strong>: I manage to find a solution:</p>
  
  <pre><code>find . -name "*.txt" | xargs -I{} \
      sh -c 'base=$(basename $1) ; name=${base%.*} ; ext=${base##*.} ; \
             mv "$1" "foo/${name}.bar.${ext}"' -- {}
  </code></pre>
  
  <p>But I wonder if there is a shorter/better solution.</p>