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.

Very obviously I can not open jar/war to check for the ^M characters.

Is there any way to proceed recursively check all the editable files (like .java/.properties/.xml/etc ) and remove characters on demand.

If I should write a script then how should I approach? I am not clear with previsous discussions.

Regards,
Bhaskar

Take a backup of all the files before you try this, just in case.

I am not sure myself if it would not harm binary files etc. that have ^M in them somewhere, if you straight strip them off. So maybe you create a list of files that might be interessting for you to be stripped:

find . -type f -exec file {} \;| grep text$| cut -d":" -f1 > outfile

My "file" command gives output like this:

./css/buch/exercise files/07_whitespace/styles/base.css: ASCII C program text
./css/buch/exercise files/07_whitespace/ex0704.html: HTML document text
./css/buch/exercise files/07_whitespace/ex0703.html: HTML document text

.. so I used "text$" to filter out the text files. You have to check your output maybe and alter the one or other thing.

Check the outfile if you can live with the listed files being stripped.
Next strip off the ^M from the files in the list, write it to a .bak file and then mv the .bak back to the original filename and so with overwrite the original.

while read FNAME; do
     tr -d '\015' < "${FNAME}" > "${FNAME}".bak
     mv "${FNAME}".bak "${FNAME}"
done < outfile

There are two fairly standard programs to assist with ^M issues, and the sharing of files between pc and unix worlds. Research into dos2unix and unix2dos.
Perhaps the use of one of these (most likely dos2unix) will assist you.

Many Thanks to both of you for this help.

Regards,
Bhaskar