To solve it in a way most close to the original problem would be probably using xargs “args per command line” option:
find . -name "*_test.rb" | sed -e "p;s/test/spec/" | xargs -n2 mv
It finds the files in the current working directory recursively, echoes the original file name (p
) and then a modified name (s/test/spec/
) and feeds it all to mv
in pairs (xargs -n2
). Beware that in this case the path itself shouldn’t contain a string test
.