Hello,
I am looking for a relible way to test a file is not empty with readable character lines.
Code:
$ dd if=/dev/zero of=./test bs=1m count=1
1+0 records in.
1+0 records out.
$ echo "TTTTTTTTTTTTTTT\nTTTTTTTTTTTTTTTT\nTTTTTTTTTTTTTTTTTTTT" >>test
$ cat test
TTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
$ file test
test: English text
$ nl test
1 TTTTTTTTTTTTTTT
2 TTTTTTTTTTTTTTTT
3 TTTTTTTTTTTTTTTTTTTT
$ grep -v ^$ test
TTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTT
$ grep ^$ test
$
What did grep do with the 1'st "TTTT..." line? Why it was treated as ^$ (empty line)?
How to get all 3 appended lines but the "dd"'s input?
I get that 1st line was appended to the "dd"'s input line and would be in new line when additional "\n" on the beginnging is added to the appending echo command. Is there a way to prevent such issue appending something to existing file (or always give new line \n for the first appended line)?
How to check a file > 0 but having only lines with spaces, tabs and non-readable characters?
Would the following test be reliable?
Code:
$ dd if=/dev/zero of=./test3 bs=1m count=1
1+0 records in.
1+0 records out.
$ [ -s test3 -a ! -d test3 -a $(sed 's/^[[:space:]]*//;s/[[:space:]]*$//' test3|grep -v ^$|wc -l) -ne 0 ] && echo is bigger || echo I can call it empty
I can call it empty
$