I have quite a few txt files. They contain the word 'Minimum' (it only shows once in each file), and I want to get the line that contains this word, and show the line in a new file.
To do this, I use this command:
grep 'Minimum' file1.txt > new1.txt
I did this to each file (file1, file2, etc.), and got lots of
newn.txt. But it turns out that some files don't have the word 'Minimum', so their
newn.txt are empty. Well, if grep can't get the word, why doesn't Linux give me an error message? Why does it continue and make the newn.txt? Giving me some empty files is really annoying.
So is there a way that I can stop it from creating the
newn.txt if it can't find the word?
Also, I'm thinking about putting it into a bash script - the grep command is the first step, and then in the second step I'll do something to the
newn.txt. So if grep can't find the word, or if there's an empty file created, I want the script to stop and not to do the second step. Is there a way to do this?