ferrelwill
ferrelwill

Reputation: 821

How ro remove extra characters in files names using awk

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

Answers (2)

jlliagre
jlliagre

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

pfnuesel
pfnuesel

Reputation: 15340

I don't see how would be helpful here, but the following 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

Related Questions