I'm doing this (e.g.:):
grep a text.txt > file.log
I can generate the file.log just if it founds the "a". Should I put it into a if? How? Can someone please give me an example? At this time this is generating blank files.
A simple workaround would be to say:
grep a text.txt > file.log || rm file.log
This would remove file.log if grep didn't find a match. So you won't have blank files.
awk '/a/{print >"file.log"}' text.txt
this command will create file.log if the file text.txt has a match with 'a'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With