Removing File Entries With sed

Hi

When running the following sed command from the command line I am able to
remove all entries with #username from the file and redirect to another file.

sed -e 's/#.*//' -e '/^$/d' namesonly > tt
mv tt > namesonly

When I use the same command in the following script I end up with the original
entries in the namesonly file. ie nothing has been removed.

 
echo "" > f-output.log
 
USERS=$(awk -F: '{print $1}' allusers)
for U in $USERS
 
do
 
finger ${U} >> f-output.log
 
awk '/^Logi/ {a=$3} /^Last log/ {print a, $6}' f-output.log > lastlogin
 
grep -v "2009" lastlogin > lastlogin_1 ; grep -v ":" lastlogin_1 | sort | uniq > newlog_1
 
cut -d' ' -f1 newlog_1 > namesonly
 
sed -e 's/#.*//' -e '/^$/d' namesonly > tt ; mv tt namesonly

done

Is there an error with this command or something else causing the problem?

Any help appreciated.

You are looping the script for each users. so make sure you append the strings in the "namesonly" file rather than overwriting it each time in the loop.

Thanks for your response....append the strings in the "namesonly" file
Can you provide an example... I tried the following which didnt work.
Do I need to change elsewhere in the script

sed -e 's/#.*//' -e '/^$/d' namesonly >> tt