finding files in dos format + .sql files without an empty last line
a.hatzim at gmail.com
Wed Feb 21 10:35:45 PST 2007
On Wed, Feb 21, at 12:39 Warren Head wrote:
> 2007/2/21, Ag. Hatzimanikas <a.hatzim at gmail.com>:
> >On Wed, Feb 21, at 10:14 Warren Head wrote:
> >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
> This works excellent already.
> I did however forget a second issue. The final line in the files I am
> worried about has to be an empty line.
Then add a second test to check if there is an empty line.
This should be enough.
&& [[ -z $(sed '$!d' $filename) ]] ;then ...
Where -z means that the condition is true if the length of the string is zero.
In our case if the last line is empty the condition will be true and then
the sed that will remove the <CR><LF> line terminators will be executed.
Check the bash man page for CONDITIONAL EXPRESSIONS.
More information about the blfs-support