finding files in dos format + .sql files without an empty last line
a.hatzim at gmail.com
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
> for filename in $(find . -type f);do
> if [[ -n $(file $filename |grep CRLF) ]]
> sed 's/^M$//' $filename > $filename.unix
> echo File converted from dos to unix: $filename
> if [[ -n $(echo $filename | grep .sql) ]]
> if [[ -n (cat -E $filename | findthelastcharacterisnot$) ]]
> insert a line feed
> overwrite the file
> echo File had a LF inserted: $filename
> # echo File ends with .sql: $filename
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