Using grep to print a keyword in a log to the output file
grep -i -n "application" /app/log1.log > L1.log
Now this gives results if it finds application in the log. But also results empty l1 log file where there are no results.
Would like assistance in creating the l1.log only when there are results.
Correct.
Using the ">" redirection operator pre-deletes the target file.
Use a temporary file to capture any number of results and use grep's exit status to determine whether or not it found anything.