First of all thanks for the replies, the set of commands dont exactly do what i want though unfornutely @radoulov
Is it possible to modify this slightly to ask the user first before deleting, I have been trying to play around with but cant figure out correct syntax
@abinaya
sorry, yes i did try your solution and im afraid i couldnt get it to work either
These are two methods which are very close but still dont work, any other ideas
#method1
find $dir -name "* *" | while IFS= read -r file; do
echo "$file remove spaces (Y/N)"
read opt
case $opt in
[yY]) mv -i "$file" `echo "$file" | sed 's/ //g'`;;
[nN]) ;;
*) echo "input not regonised";;
esac
done
this script does not wait for the user input example output looks like
spaceDir/ 234.txt remove space (Y/N)
input not regonised
spaceDir/12 34.txt remove space (Y/N)
input not regonised
method 2
for file in `find $dir -name "* *"`; do
printf "%s: remove spaces(Y/N): " "$file"
read opt
case $opt in
[yY]) mv -i "$file" `echo "$file" | sed 's/ //g'`;;
[nN]) ;;
*) echo "input not regonised";;
esac
done
This method waits for the user input but does not print out the file correctly e.g
spaceDir/file remove spaces(Y/N): y
mv: cannot access spaceDir/file
spaceDir/name remove spaces(Y/N): y
mv: cannot access spaceDir/name