I need to inside one of my scripts be able to view a file
if it's empty have a message that says - nothing in the file
and if it's not view the contents
I was trying to figure out the best and most efficient way to do this but I'm getting stuck.
Here is an example:
Suppose you have a file named "myfile" containing only a single line "Hello World", that is, 11 characters, therefore there will be 11 bytes in the file and two words "Hello" and "World". Here is the result of the wc commnd
$ wc -c myfile
11 myfile
11 is the number of bytes and myfile is just the name of the file. Yet, it is only the number of bytes which is interesting for this problem. As a result by using the command cut we extract this first field (by a pipe)
And, llsmr777, If You're only interested in the content of myfile, and not really the status of it (having text or not), just cat'ing it would do fine, because You will see whether it has anything in it. Like:
echo Content of myfile:
cat myfile
echo End of content