I'm comparing the results of two files for lines in one that are not in the other using grep -v -f file1.txt file2.txt > result.txt
Let's say my files look like;
file1.txt
alex
peter
zoey
file2.txt
alex
john
peter
zoey
So result.txt should contain john
This is to be run inside a Jenkins job, and jenkins ends up not happy with creating an empty result.txt if there are no differences between the two.
I can't just do a blind diff/no diff output, I specifically need to know which lines differ if there are any.
Is there a neater way to run this command to not create a file if there are no results?
result.txtfile? Or would a temporary file be sufficient for what you are trying to accomplish?grep foo >out, the fileoutis created beforegrepis ever started (otherwise,grepwould have no stdout to which to write its output).