Okay, I'm going in circles. I'm using this command
find . -print0 -name '*.1.*' | sed -e 'p;s/\.1//' | xargs -0 -n2 mv
To try and rename hundreds of files that had ".1." added just before the file extension when they were archived after someone accidentally deleted 200GB worth of data.
I'm caught between the mac xargs interpreting spaces in filenames as separate arguments, and not being able to set the delimiter to only newlines, not spaces. I cannot figure out how to have find print the '\0' character as well as newlines between. Any ideas on how to get this to work? I've been searching in circles and it seems simply being on a mac environment is making this more complicated than necessary.
Alternatively trying rename command but still having issues
find . -name '*.1.*' -type f -exec rename -n 's/\.1//' '{}' \;
ANSWER as per @Wildcard below
find . -name '*.1.*' -type f -exec sh -c '
for f do
suf="${f##*.1}"
new="${f%.1.*}$suf"
if [ -e "$new" ]; then
printf "Cannot move file <%s>\n" "$new"
else
mv -n "$f" "$new"
fi
done
' find-sh {} +
-z, --null-data
argument for precisely this purpose.