Search code examples
bashshellunixawkcut

Unix to verify file has no content and empty lines


How to verify that a file has absolutely no content. [ -s $file ] gives if file is zero bytes but how to know if file is absolutely empty with no data that including empty lines ?

$cat sample.text

$ ls -lrt sample.text
-rw-r--r-- 1 testuser userstest 1 Jul 31 16:38 sample.text

When i "vi" the file the bottom has this - "sample.text" 1L, 1C


Solution

  • Your file might have new line character only.

    Try this check:

    [[ $(tr -d "\r\n" < file|wc -c) -eq 0 ]] && echo "File has no content"