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

Warren Head warrenhead at gmail.com
Tue Feb 27 05:49:14 PST 2007


2007/2/23, Dan Nicholson <dbn.lists at gmail.com>:
>
> 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
> --
>

I am stucking with this version now. The auditing part is actually all we
want to be automated. Other things have been commented out.
For the list, if usefull for anybody. People, thanks to everyone. You know
who you are!

Cheers, Warren

#!/bin/bash
for filename in $(find . -type f);do
       # check whether the file is in DOS lineending format
       if [[ -n $(file $filename |grep CRLF) ]]
       then
           #echo "File is not in unix format: $filename"
           # create a unix file out of it
           #sed 's/^M$//' $filename > $filename.unix
           #echo "File converted from dos to unix: $filename"

           # check whether the file is a .sql file
           if [[ -n $(echo $filename | grep .sql) ]]
           then
               #echo "File ends with .sql: $filename"

               # check whether the file does not have a linefeed as the last
character
               if cat -E $filename | tail -n1 | grep -q '[^$]$';
               then
                   echo "SQL file is not ending with a linefeed: $filename"
                   #echo "Inserted line feed at end of: $filename"
                   #echo  >> $filename
               fi
           fi
       fi
done
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxfromscratch.org/pipermail/blfs-support/attachments/20070227/229c3be0/attachment.html>


More information about the blfs-support mailing list