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

Dan Nicholson dbn.lists at gmail.com
Fri Feb 23 09:39:49 PST 2007


On 2/23/07, Ag. Hatzimanikas <a.hatzim at gmail.com> wrote:
> On Fri, Feb 23, at 09:11 Warren Head wrote:
>
> 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
> fi
>
> I maybe missing something obvious here so please correct me.

An alternative:

if cat -E $file | tail -n1 | grep -q '[^$]$'; then
    echo "No line feed at end of $file"
    echo >> $file
fi

Seemed to work in my test over here.

--
Dan



More information about the blfs-support mailing list