Modifying replace string in xargs
In cases like this, a while
loop would be more readable:
find . -name "*.txt" | while IFS= read -r pathname; do base=$(basename "$pathname"); name=${base%.*}; ext=${base##*.} mv "$pathname" "foo/${name}.bar.${ext}"done
Note that you may find files with the same name in different subdirectories. Are you OK with duplicates being over-written by mv
?