I have a file which comes every day and the file data look's as below.
Vi abc.txt
a|b|c|d\n
a|g|h|j\n
Some times we receive the file with only a new line character in the file like
vi abc.txt
\n
We need to handle the shell script such a way that if the entire file contains only a new line character then remove the new line character else don't touch the file .
Check if the file contains printable characters grep -q "[[:print:]]" $file;
if not if ! truncated to zero >$file
I apologize for the not quite detailed answer, I just learn English
Even if your system doesn't have the stat command, you could also use:
[ $(wc -c < "$file") -eq 1 ] && > "$file"
The command:
wc -c < "$file"
prints the number of bytes found on its standard input (in this case the contents of the file you're interested in) and if that is equal to 1, the redirection recreates the file as an empty file.