How to Remove Ctrl M characters in files from directories and its subdirectories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Remove Ctrl M characters in files from directories and its subdirectories
# 1  
Old 07-28-2006
How to Remove Ctrl M characters in files from directories and its subdirectories

Hi,
How to recursively remove Ctrl M characters in files from a directory and its sub directory ?

I know unix2dos command is there but to remove in bunch of files ... ?


Thanks
# 2  
Old 07-28-2006
You need to write a script.
# 3  
Old 07-28-2006
Try modifying with the following script............

for files in *.html;
do
mv $files $files.old
dos2unix $files.old $files
rm -rf $files.old
done
# 4  
Old 07-28-2006
Code:
find /path/to/files -print | \
while read file
do
     dos2ux "$file" > ./tmpfile
     mv ./tmpfile "$file"
done

# 5  
Old 07-28-2006
Reply to the script by corleone

Hi corleone,

Iam getting error
/could not open /dev/kbd to get keyboard typed ......


Do I need to save the script in .sh format ?
How do I run the script ? Kindly reply since Iam naive. Iam using unix on solaris.

Thanks
# 6  
Old 07-28-2006
This error comes from dos2unix and doesn't stop the utility from working. You could simply redirect stderr

dos2unix filename > newfilename 2> /dev/null
# 7  
Old 07-28-2006
A google seach provided these links:

Link 1
Link 2
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove files in directories

I am trying to remove files from a couple of directories after a process completes. Below is what I have so far, but the command does not run and cygwin closes too fast to read the error. Also, is it possible to have the printf be displayed until the files are removed then printf in italics is... (8 Replies)
Discussion started by: cmccabe
8 Replies

2. Shell Programming and Scripting

List files with *.i extension in a directory and all its subdirectories + 30days old then remove

I need to write a script to : list files with *.i extension in a directory and all its subdirectories + 30days old, save it in a file and then remove (2 Replies)
Discussion started by: lena keung
2 Replies

3. Shell Programming and Scripting

Zip all the files including directories - subdirectories

Hi, Is is possible to zip a folder and all its contents within the folder ( including sub-directories and files) into a zip file? and can regain the same structure if unzipped? Thanks (6 Replies)
Discussion started by: rudoraj
6 Replies

4. Shell Programming and Scripting

Remove files from subdirectories given a list of filenames

Dear all, I have a dir structure like main_dir At_nn Ag_js Nf_hc .... mcd32 mgd43... mcd32 mgd43... mcd32 mgd43... and each subdir (e.g. mcd32, mgd43) contains files. Now, i... (15 Replies)
Discussion started by: yogeshkumkar
15 Replies

5. UNIX for Dummies Questions & Answers

show all text files in directories and subdirectories

Hi! I am trying to find all text files in my home directory that contain the string "C-d" so I tyied this : cd ~ find . -type f -exec grep -l "C-d" {} + but it took very long so I tryed this : ls -aR | xargs file |grep text but it didn't descend in the directories and it said :... (3 Replies)
Discussion started by: kelamahim
3 Replies

6. UNIX for Dummies Questions & Answers

Help with untarring multiple files from tarred directories and subdirectories

Hi, I want to untar all log files from following tarred directory hierarchy Log_files.tar.gz/subject*.tar.gz/project*/*.log It means there are subject1.tar.gz to subject9.tar.gz and in those tarred subect directories there are project1 - project5 directories and in those directories there... (2 Replies)
Discussion started by: rv_trojan
2 Replies

7. Shell Programming and Scripting

Rename files and directories with special characters

Hello guys, I was looking for a shell script that removes all the special characters from the files and the subdirectories recursively. I could not locate it any more. Dose any body have a similar script that dose that? Thanks for the help. AV (0 Replies)
Discussion started by: avatar_007
0 Replies

8. Shell Programming and Scripting

How to remove ^M characters recusrsively from all subdirectories and file in directry

Hi, First apologies for starting the old issue (already discussed in this forum). How can I remove ^M characters from a directory which contains lot of subdirectory and files (this includes jar, war, .xml, .properties etc). Noticeable is that, all files might not contain ^M characters. ... (3 Replies)
Discussion started by: bhaskar_m
3 Replies

9. UNIX for Dummies Questions & Answers

How to remove directory with subdirectories and files?

I'm trying to remove several directories which contains sun-dirs and files inside. I used the command rm -r <dirname> But, it always ask "examine file in directory <dirname> yes/no?" line by line. So, i need to write "y" for every line. How can i skip this step and remove all directories with... (9 Replies)
Discussion started by: ppa108
9 Replies

10. Shell Programming and Scripting

Check all files in directories for string and remove.. possible?

Say I am in /var/adm/bin and I want to search through all the various scripts and such in that directory for a string, say, xxx@yyy.com I want to find every file with that in there and replace it with a single space. Is that possible? Or, is it possible to search every file and get a list... (7 Replies)
Discussion started by: LordJezo
7 Replies
Login or Register to Ask a Question