I have several files that are named like this: file - name.txt
How do I remove the " - " using a bash script in UNIX from all the files?
If I understand correctly, try rename ' - ' '' *
Use parameter expansion to remove the part of the string you want to be rid of. Make sure to use double-quotes to prevent mv from misinterpreting input.
for i in ./*' - '*; do
mv "$i" "${i// - }"
done
separateString="${i%% - *}"Sed it up!
# Iterate each file in the current directory.
for i in *; do
# Move the file to the new filename, replacing ' - ' with '_'
mv "$i" `echo $i | sed 's/ - /_/g'`
done