I am running somo Mysqli querys that generates me CSV output files. Some of them are just empty CSV files because nothing matches with the query parameters. I want a script that opens and replaces the content (only if the file is empty) of all CSV files in a folder.
It can be in PHP but also awk, sed or similars.
file=foo; if [ -w "$file" -a ! -s "$file" ] ; then echo "./." > "$file" ; fi
foo exist (
-w) and (
-a) is a zero-length file (
! -s) write
./. over its empty contents. You can test it by
touch foo and then running that script.