Reputation: 821
I am trying to remove an extra character \
from multiple file names. Is there any way to do this ? Than in advance. Surprisingly when i type ls -l, I do not see backslash in the file names.
input
file1
asg19.mail14_+_\:38033421-38033567.mail
file2
asg19.mail14_+_\:38088821-38033567.mail
output
file1
asg19.mail14_+_:38033421-38033567.mail
file2
asg19.mail14_+_:38088821-38033567.mail
Upvotes: 0
Views: 131
Reputation: 30833
This will suppress all backslashes from the strings in file1, file2, ...:
tmp=$(mktemp)
for file in file1 file2
do
awk '{gsub("\\\\","");print}' $file > $tmp
cat $tmp > $file
done
Upvotes: 1
Reputation: 15340
I don't see how awk would be helpful here, but the following bash snippet should work:
for file in *\\*; do
mv "${file}" "${file/\\/_}"
done
You just need to escape the backslash with another backslash.
This code works for me for a file with name
asg19.mail14_+_\:38033421-38033567.mail
but you're saying that you don't see the backslash when doing ls -l
, while I do see it.
Upvotes: 1