1

How do I check if a file is empty in a korn script

I want to test in my korn script if the output CSV file is empty or not and if it is not empty then it should give the count of values. Thanks.

user2260271
  • 71
  • 1
  • 1
  • 4
  • Does this answer your question? [How to check if a file is empty in Bash?](https://stackoverflow.com/questions/9964823/how-to-check-if-a-file-is-empty-in-bash) – betontalpfa Apr 08 '21 at 15:14

3 Answers3

11

The test(1) program has a -s switch:

-s FILE
      FILE exists and has a size greater than zero
cnicutar
  • 178,505
  • 25
  • 365
  • 392
-1

This is just another way of doing it, albeit a roundabout one:

if [ `ls -l <file> | awk '{print $5}'` -eq 0 ]
then
//condition for being empty
else
//condition for not being empty
fi
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Vels
  • 17
  • 1
  • 1
  • 1
-2
if [ ! -f manogna.txt ]
then
    echo "  Error: manogna.txt  does not exist  "
else
    echo " manogna.txt   exist " 
    echo " no of records in manogna.txt are `cat manogna.txt   | wc -l`"
fi