If you have gsed :
find . -name \*.erb -print0 | gsed -z 'p;s/.erb$/.haml/' | xargs -0 -n2 html2haml
If you don't have gsed and only sed , this will work , but only if none of your file names have spaces .
find . -name \*.erb -print | sed 'p;s/.erb$/.haml/' | xargs -n2 html2haml
Discussion of these and other methods:
I have different versions of sed - my GNU sed is called gsed , if your sed is GNU - use sed instead of gsed .
You can check your sed for sed --version if it prints something like:
sed (GNU sed) 4.2.2 Copyright (C) 2012 Free Software Foundation, Inc.
You have GNU sed.
The above is for the next find
$ find . -name \*foo -print ./a/test.foo ./b/c/test.foo ./b/te st.foo
the above command produces:
$find . -name \*foo -print0 | gsed -z 'p;s/foo$/foo2/' | xargs -0 -n2 echo bar bar ./a/test.foo ./a/test.foo2 bar ./b/c/test.foo ./b/c/test.foo2 bar ./b/te st.foo ./b/te st.foo2 bar ./b/test.foo ./b/test.foo2
No additional scripts or functions .;)
or you can replace sed with perl , so the following
find . -name \*foo -print0 | perl -n0le 'print;s/foo/foo2/;print' | xargs -0 -n2 echo bar
gives the same result:
bar ./a/test.foo ./a/test.foo2 bar ./b/c/test.foo ./b/c/test.foo2 bar ./b/te st.foo ./b/te st.foo2 bar ./b/test.foo ./b/test.foo2
IF YOU REALLY want to do this at a time, try:
find . -name \*html.erb -exec sh -c 'echo html2haml "{}" "$(echo "{}" | sed 's/\.erb/\.haml/')"' \;
or eliminating two useless echoes in the last command:
find . -name \*html.erb -exec sh -c 'html2haml "{}" "$(sed 's/\.erb/\.haml/'<<<"{}")"' \;