How to remove Ctlr-M characters from file from a unix script

There are 10 files present which have Ctlr-M characters appended to each line of all files.

I have a unix script which processes the files in a loop.
And there is an inner loop which processes each line in the file concerned.


#inputFile is a variable which has the file name of the input file(eachFile)

...outer loop
inputFile=eachFile

...inner loop
while read record
.
.
done

How do I remove all the Ctlr-M characters and write the same contents to the same input file.Also the input file name will change for each file so we cant hard code the input file name

Thanks
Abhinav

perl -pi -e 'tr/\cM//d;'  <filename>

This command executes on your filename and removes all ^M characters placed anywhere. You do not have to redirect the output again in some new input file. Just execute this command with your input file name.

For your requirement what you can do is, execute this command repeatedly for your all input files. Store your file name in configuration file and read the file name using a loop.