Is this to strip carriage return characters from a DOS file? If so, create a new file containing the following shell script:
[tt]
#!/bin/sh
sed -e's/
^M$//' $1 > /tmp/$1.new
# Copy original file to a backup.
cp $1 $1.orig
# Move the new copy over the top of the original file.
mv /tmp/$1.new $1
# Remove the temporary file.
rm /tmp/$1.new
[/tt]
The
^M is the control-M character, or carriage return. To enter this character if you are using vi, press Ctrl+V followed by Ctrl+M.
Run the script as "myscript file.txt", where file.txt is the name of the file you want to strip <CR> out of. Everywhere you see "$1" in the script it is referring to the first argument. ie, the filename.
The sed line uses the "swap" operator "s" on every line in the named file. If it finds a ^M character at the end of a line, it is replaced with nothing. In other words, it will be removed. The "$" character following ^M indicates that the match will only mach ^M chars at the end of the line.
Following sed, we redirect output using ">" to a file in the /tmp directory.
Everything else is just moving the new file into place while keeping a copy of the original.
I leave it as an exercise for the reader to check if the named file exists and deal with this appropriately.

[sig]<p> Andy Bold<br><a href=mailto: > </a><br><a href= > </a><br>"I've probably made most of the mistakes already, so hopefully you won't have to..." Me, most days.[/sig]