On February 27, 2007, Warren Head wrote: > 2007/2/23, Dan Nicholson <[EMAIL PROTECTED]>: > > On 2/23/07, Ag. Hatzimanikas <[EMAIL PROTECTED]> 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
Warren: I have a "c" program that will do this. I had it packaged but it was too big to send to the mailing list. If you are still interested, i can post the source. It follows your pseudo code, but it also walks the directory tree if your files are in more than one directory. The actual souce isn't too big, but the packaging made it huge with all that libtool, autoconf stuff. I'll post the source if anybody think they might need something like this. Shawn -- http://linuxfromscratch.org/mailman/listinfo/blfs-support FAQ: http://www.linuxfromscratch.org/blfs/faq.html Unsubscribe: See the above information page
