How to remove hidden backslash in multiple files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove hidden backslash in multiple files?
# 1  
Old 12-13-2013
How to remove hidden backslash in multiple files?

Hi I have around 300 files in a folder. When I type ls -l I see the following

Code:
Mouse.chr10_+_:101862321-101863928.maf
Mouse.chr10_+_:101862322-101863928.maf
Mouse.chr10_+_:101862323-101863928.maf

But when I run my scripts, they couldn't recognise the filename because of hidden backslash like the below.

Code:
Mouse.chr10_+_\:101862321-101863928.maf
Mouse.chr10_+_\:101862322-101863928.maf
Mouse.chr10_+_\:101862323-101863928.maf

Is there anyway to remove all these hidden backslashes from multiple file names ?

Last edited by quincyjones; 12-13-2013 at 07:50 AM..
# 2  
Old 12-13-2013
Does the hidden the \ appear in this command?

Code:
ls |  cat -vet -

The reason I ask is there is possibly some other unprintable character in the filename right after the \. There is no need to escape a colon that I am aware of.

If the files were brought over from another system with a different locale setting, then this is likely. So before we suggest something that will cause problems we really need to see what is going on.
# 3  
Old 12-13-2013
I see like this

Code:
Mouse.chr10_+_:101862321-10186392.maf$
Mouse.chr10_+_:101862321-10186392.maf$
Mouse.chr10_+_:101862323-10186392.maf$

# 4  
Old 12-13-2013
There has to some weird character in there - if
Code:
ls | od -c

shows nothing
odd try this:
Code:
ls | while read fname
do
 prefix="Mouse.chr10_+_"
 suffix=$(echo "$fname" | awk -F ':' '{print $2}')
 newfile="${prefix}:${suffix}" 
 mv "$fname" "${newfile}" 
done

And. This is very odd if there really is no other character after the \.
# 5  
Old 12-13-2013
sorry but I have combinations of names like this

Code:
Mouse.chr1_+_
Mouse.chr2_+_
Mouse.chr3_+_
Mouse.chr4_+_
Mouse.chr5_+_
Mouse.chr6_+_
Mouse.chr7_+_
Mouse.ch8_+_
Mouse.chr9_+_
Mouse.chr10_+_
Mouse.chr11_+_
Mouse.chr12_+_
Mouse.chr13_+_
Mouse.chr14_+_
Mouse.chr15_+_
Mouse.chr16_+_
Mouse.chr17_+_
Mouse.chr18_+_
Mouse.chr19_+_
Mouse.chrX_+_
Mouse.chrY_+_


Mouse.chr1_-_
Mouse.chr2_-_
Mouse.chr3_-_
Mouse.chr4_-_
Mouse.chr5_-_
Mouse.chr6_-_
Mouse.chr7_-_
Mouse.ch8_-_
Mouse.chr9_-_
Mouse.chr10_-_
Mouse.chr11_-_
Mouse.chr12_-_
Mouse.chr13_-_
Mouse.chr14_-_
Mouse.chr15_-_
Mouse.chr16_-_
Mouse.chr17_-_
Mouse.chr18_-_
Mouse.chr19_-_
Mouse.chrX_-_
Mouse.chrY_-_

# 6  
Old 12-13-2013
Quote:
Originally Posted by quincyjones
But when I run my scripts, they couldn't recognise the filename because of hidden backslash like the below.

Code:
Mouse.chr10_+_\:101862321-101863928.maf
Mouse.chr10_+_\:101862322-101863928.maf
Mouse.chr10_+_\:101862323-101863928.maf

What is producing this output? Can you show the relevant part of your script?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rsync - how to copy hidden folder or hidden files when using full path

Hello. I use this command : rsync -av --include=".*" --dry-run "$A_FULL_PATH_S" "$A_FULL_PATH_D"The data comes from the output of a find command. And no full source directories are in use, only some files. Source example... (2 Replies)
Discussion started by: jcdole
2 Replies

2. Shell Programming and Scripting

[Solved] How to remove multiple files?

Hi Gurus, I have below files in one directory. the file name has date and time portion which is exactly the file be created. I need keep only lasted created file which is abc_20140101_1550 and remove rest of the file. abc_20140101_1300 abc_20140101_1200 abc_20140101_1400 abc_20140101_1500... (2 Replies)
Discussion started by: ken6503
2 Replies

3. Shell Programming and Scripting

Remove java code from multiple files

Hello, We have a client who has had an FTP injection attack on their account. Over 600 files have this code added to the files: <script>var t="";var... (10 Replies)
Discussion started by: dhasbro
10 Replies

4. UNIX for Dummies Questions & Answers

How to remove characters from multiple .txt files

Friends, I want to remove charecters from multiple .txt files. Foe example : In this .txt files there are many "ctrl m" present in last of each line in one .txt file. I want to remove "ctrl m" from each line from all .txt files. Need your help regarding this. (4 Replies)
Discussion started by: meetsubhas
4 Replies

5. Shell Programming and Scripting

To remove multiple files in FTP

We have a files in FTP server..... after getting the files from FTP by mget *.* i hav to remove all files (multiple files) at once... is there any command to delete multiple files at once (2 Replies)
Discussion started by: nani1984
2 Replies

6. Shell Programming and Scripting

remove backslash character from file

How do I remove a backslash character \ from a file? I have used sed -e "s|\||g" filename > newfile I have done several permutations on this to no avail such as: sed -e "s|`\`||g" filename > newfile sed -e "s|""\""||g" filename > newfile What am I doing wrong?:confused: ... (2 Replies)
Discussion started by: MissI
2 Replies

7. Shell Programming and Scripting

How to remove certain lines in multiple txt files?

Hi , I have this type of files:- BGH.28OCT2008.00000001.433155.001 BGH.28OCT2008.00000002.1552361.001 BGH.28OCT2008.00000003.1438355.001 BGH.28OCT2008.00000004.1562602.001 Inside them contains the below: 5Discounts 6P150 - Max Total Usage RM150|-221.00 P150 EPP - Talktime RM150... (5 Replies)
Discussion started by: olloong
5 Replies

8. Shell Programming and Scripting

Finding Hidden files and protecting the folder containing hidden files from deletion

Hi. I have a script which is deleting files with a particular extension and older than 45 days.The code is: find <path> -name "<filename_pattern>" -mtime +45 -exec rm {} \; But the problem is that some important files are also getting deleted.To prevent this I have decide to make a dummy... (4 Replies)
Discussion started by: pochaw
4 Replies

9. Shell Programming and Scripting

remove hidden messages

When I print (cat) my log file, the following shows up Executing sftp ... sftp> lcd /home/abc /home/abc sftp> put test.xml test.xml | 20MB | 620kB/s | TOC: 00:00:33 | 100% sftp> quit test.xml transferred then I try to grep "100%" from this file where I got "grep:... (1 Reply)
Discussion started by: mpang_
1 Replies
Login or Register to Ask a Question