finding files in dos format

Ag. Hatzimanikas a.hatzim at gmail.com
Wed Feb 21 03:09:59 PST 2007


On Wed, Feb 21, at 10:14 Warren Head wrote:
> Hi,
> 
> I am looking for a command that can recursively find text files that are not
> in a unix format, but ending in a dos format.
> I know that the dos2unix command can change the line endings, but I don't
> know how to find the files that currently aren't in the unix format.
> 

This simple loop should do the job,checked in bash/zsh.
===========================================
for filename in $(find . -type f);do
	if [[ -n $(file $filename |grep CRLF) ]]
	then
	sed 's/^M$//' $filename > $filename.unix
	fi
done
===========================================

You can use the dos2unix command instead of sed,if you like,
but I don't know it's syntax.
There should be a choice for a backup I guess.

If you decide to use the sed,you can type the ^M in your shell,or in
your editor with
<CTRL-V><CTRL-Return>
or with 
<CTRL-V><CTRL-M>.

If you have checked your files and you are satisfied,then you 
can rename them in it's previous original name.

===========================================
for filename in $(find . -type f -name "*unix");do
	mv -v $filename ${filename%.unix}
done
===========================================





More information about the blfs-support mailing list