There are quite a few issues with the your existing code.
Avoid using cat when commands accept a file name, or you can direct file straight to them. This didn't cause anything to fail to do what you wanted, but is poor form and wastes processing power invoking the cat executable.
echo $linecont > temp
This strips any multiple white space from output you should quote the line to protect spaces like echo "$linecont" > temp
if [$line1 = ""] then
You need to quote $line1 here otherwise if it's blank the file expression will complain about = "" is not valid syntax.
echo $linecont > file2
This will not append to the file and will just keep the list line found use ">>" to append but you must empty/remove any old files at start of your program.