If the file has null record in it
then echo "empty file with null record" -- abc.dat
else echo "empty file" -- pqr.dat
else echo "file has data in it" -- xyz.dat
The following script assumes that /bin/sh is a Posix-compatible shell.
If the raw read is successful then it has got a record, then the record is tested for being zero (empty, null).
#!/bin/sh
if IFS= read -r line < "$1"
then
if [ -z "$line" ]
then
echo "file with null record"
else
echo "file has data in it"
fi
else
echo "empty file"
fi
The script takes a file name as argument, otherwise reads from stdin.
For academic interest, the following works identically because the if ... fi is a block where input and output can be redirected.
The difference is, that the input file is open throughout the block, so another read in the block would read the next line.
#!/bin/sh
if IFS= read -r line
then
if [ -z "$line" ]
then
echo "file with null record"
else
echo "file has data in it"
fi
else
echo "empty file"
fi < "$1"