Hello all,
I have many files labeled: 001 _MP, 002 _MP...160 _MPHow do I rename all the files to 001_MP, 002_MP? That is remove the space?
I may need to script this as this occurs quite oftenThanks for your time
This topic was discussed in this thread:
if you are using bash, no need to use external tools for files in *MP do mv "$files" "${files// /}" done
OK Thanks here's what I end up using: #!/bin/sh
find . -name "* *"|while read file
do
target=`echo "$file"|tr -s ' ' '_'`
mv "$file" "$target"
done
This one is for Korn Shell. #!/bin/ksh
for file in *MP
do
print $file | while read part1 part2
do
mv "$file" "$part1$part2"
done
doneghostdog's bash solution is also excellent. Both his solution and mine avoid the need to go outside the shell to accomplish the task which is always the best way to do things. Your solution uses the find, echo and the tr commands unnecessarily.
| « Unix Shell Scripting $! | Need help printing in awk... » |