finding files in dos format + .sql files without an empty last line
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" == "\$"
> > 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
> Seemed to work in my test over here.
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!
for filename in $(find . -type f);do
# check whether the file is in DOS lineending format
if [[ -n $(file $filename |grep CRLF) ]]
#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) ]]
#echo "File ends with .sql: $filename"
# check whether the file does not have a linefeed as the last
if cat -E $filename | tail -n1 | grep -q '[^$]$';
echo "SQL file is not ending with a linefeed: $filename"
#echo "Inserted line feed at end of: $filename"
#echo >> $filename
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the blfs-support