A right start for a pipeline version and the same renaming algorithm could have been :
printf "%s\n" *.* | grep '\..*\.' |
One line version :
Code: Select all
printf "%s\n" *.* | grep '\..*\.' | while read fn; do Suf=".${fn##*.}"; Pre="${fn%.*}"; echo mv "$fn" "${Pre//./_}$Suf"; done
Multi-line version with comments :
Code: Select all
printf "%s\n" *.* \
| grep '\..*\.' \
| while read fn; do Suf=".${fn##*.}"; Pre="${fn%.*}"; \
echo mv "$fn" "${Pre//./_}$Suf"; done
- line 1 : prints out everything that has an extension one per line
- line 2 : keep only those having at least 2 dots : we are sure that from here on all files remaining have to be renamed according to replacing . with _ and their names will be different, so no
mv error
- line 3 : while loop begin extracting
Suf (extension) and
Pre (prefix)
- line 4 : dummy running with echo and ending loop
If it's OK, run same command without echo.