On removing ^M
Giorgos Keramidas
keramida at ceid.upatras.gr
Sun May 8 14:34:22 PDT 2005
On 2005-05-08 14:20, Fafa Hafiz Krantz <fteg at london.com> wrote:
>
> Good day all!
>
> I am aware of the port unix2dos (dos2unix) as a tool to
> remove ^Ms from ASCII files.
>
> But if you execute dos2unix in a directory where some files
> contain ^M (CR/LF) and some files don't (CR), then dos2unix
> will make a mess of those files who don't.
>
> I am wondering what is needed (what tool or what code) to
> do a mass (recursive) removal of ^Ms?
No "tool" is needed, as long as you have FreebSD's shell, sed & grep:
$ find . | while read fname ;do
if grep '^M' "${fname}" >/dev/null 2>&1 ;then
sed -i '' -e 's/^M//g' "${fname}"
fi
done
More information about the freebsd-questions
mailing list