The shell script below is test.sh, currently it is able to check for the 10th to 15th character equals to ‘000000’. However it should also check for ‘ ‘ 6 null spaces as well as empty file. Question is:
1) How to check for empty file?
filename=$1
extracted=`head -1 $filename | cut -c10-15`
if [ $extracted -eq '000000' ] ###how to check for ' ' 6 null character with or operator?
then
mv $filename new.$filename
fi
e.g.
Input file:
Case 1 (some characters before and after the 6 zeros 000000) truefile.txt:
123456789000000161718
Case 2 (empty file) trueemptyfile.txt:
"there's nothing in this file. Empty. "
Case 3 (Some characters before and after ‘ ‘ 6 null characters) truepartialempty.txt
123456789 16171819
Thank you
And one more thing all these file is under /temp folder
/temp> ls
test.sh truefile.txt trueemptyfile.txt truepartialempty.txt
How to run test.sh to check for all the files. thank you.
Is it?
sh test.sh *.*
You have to define better what you mean by null chars.
When you show
' ', those are space chars. There are several intrepetations of the word null. In DB land NULL is special word that means “an unknown value”. In programming NUL, or NULL, or null, probably mean the char\000. That digital value is used as a special marker to indicate in ‘C’ programs (at least) “end-of-string”.Assuming that you mean space chars, you can search for them exactly has you have defined them:
But note of course that $exacted cannot equal both 000000 AND ‘ ‘, right?
It maybe that you’ll find it easier to test for these values like
Note, because of the special meaning for \000 to c-lang programs, including grep and about everything in unix, you can’t reliably do
(Actually, that might work, becuase “$extract” is not a file, but if you try
grep -q '\000' myFile, that probably won’t work reliably, as by definition a file with a ‘\000’ inside is a binary file, not a text file, and grep, et.al. are tools for scanning text files).There are likely tricks to find these if that is really what you want, so please edit your question to indicate if that is your requirement.
IHTH