I am receiving output from a script that should not be there. The output is from the ls command and it depends on the directory it uses. The bad output comes from /home/linux1/Chapter7 or /home/linux1/Chapter7/source. Output from /home/linux1 or anything else appears to work. The file that is the bad output is called awk_data6. I remove before and after the search to ensure it does not exist. The "END" statement should create this file and therefore should never be found by the ls command. Is there an explaination?
Code:
linux1@mikenash-rhel67:/home/linux1/Chapter7/source $~>sh list_small_files6
rm: cannot remove `/home/linux1/Chapter7/source/awk_data6': No such file or directory
LIST OF FILES WITH LESS THEN 32 BYTES
-rw-rw-r-- 1 linux1 linux1 0 Apr 8 15:38 awk_data6
-rw-rw-r-- 1 linux1 linux1 0 Apr 5 13:16 linktest
Total 0 bytes for 2 files.
Code:
rm ~/Chapter7/source/awk_data6
ls -lR /home/linux1/Chapter7/source 2> /dev/null | awk -v byte_counter=0 '
BEGIN{print "LIST OF FILES WITH LESS THEN 32 BYTES"}
NF == 9 && $1 !~ /^d/ && $5 < 32{print $0; byte_counter=byte_counter+$5; ++file_counter}
END{print "Total " byte_counter " bytes for " file_counter " files." }' > ~/Chapter7/source/awk_data6
cat awk_data6
rm ~/Chapter7/source/awk_data6