finding files in dos format + .sql files without an empty last line

Ag. Hatzimanikas a.hatzim at
Fri Feb 23 08:14:17 PST 2007

On Fri, Feb 23, at 09:11 Warren Head wrote:
> >
> I took a shot at it, but I am missing the linefeed check and insert linefeed
> stuff.
> #!/bin/bash
> for filename in $(find . -type f);do
>       if [[ -n $(file $filename |grep CRLF) ]]
>       then
>           sed 's/^M$//' $filename > $filename.unix
>           echo File converted from dos to unix: $filename
>       fi
>       if [[ -n $(echo $filename | grep .sql) ]]
>       then
>           if [[ -n (cat -E $filename | findthelastcharacterisnot$) ]]
>           then
>               insert a line feed
>               overwrite the file
>               echo File had a LF inserted: $filename
>           fi
>           # echo File ends with .sql: $filename
>       fi
> done

Hi Warren and sorry for my absent,

We are not looking for files with an empty line at the end and,
we are looking for files without a linefeed at the last line.Right?
(How the hell there is no linefeed,I am puzzled for this).

Here what I came up quickly (untested).

Test1.Don't look for files with an empty last line.
[[ -n $(sed '$!d' $filename) ]]
Test2,take the last character.
lastcharacter=$(cat -A $filename |sed '$!d;s/.*\(.\)$/\1/')

Now constatanate them.

if [[ -n $(sed '$!d' $filename) ]] && [[ ! "$lastcharacter" == "\$" ]];then
	sed -i '$G' $filename

I maybe missing something obvious here so please correct me.

More information about the blfs-support mailing list