Incomplete last line

I need help with appending the last line to the file only if the last line is incomplete.

I tried awk 1 filename > new_filename but it appends to every file and I only want to append to the file if the last line is incomplete

so in which situation, you will think the last line is incomplete? and what do you need to add to last line?

I am getting these files from a windows server I believe and when I open in the vi editor it says incomplete last line, I have several files and when I merge them together for loading, if the file is incomplete it ignores the last line in the file while creating the combined file. If I make the file complete this situation will be avoided

Vi is complaining that the last line in the file does not have a terminating newline. Running all of your files through the awk programme that you mentioned will fix the ones that are missing the newline, and will not change the ones that are ok. That is the easy way.

If you really want only to alter just the files that are missing the terminating newline, then try this out:

#!/usr/bin/env ksh

for x in *
do
        if ! tail -1 $x | od -t x1 | grep -q "0a$"
        then
                echo "fixing $x"
                echo "" >>$x
        else
                echo "$x is ok"
        fi
done

It will run the last line of each file in the current working directory through od, and if the last byte is not 0a (newline), then it will add a newline to the file. Using the echo will be faster as kshell will open and seek to the end where awk would read and write all of the lines in the file -- unnecessary disk i/o.

This should work in bash too, but I didn't test it there.