Is there any way for grep
to have an AND feature? I mean something like this:
I have these lines:
I have this one line
I don't have this other line
I have this new line now
I don't have this other new line
This line is new
So I want for grep
to find lines that contain BOTH the words "new" and "line", not only "new line". I know I can do this like this:
grep new file | grep line
But that's not what I'm looking for. I'm looking to do this with one single grep
command. This is because this script will let the user input the two terms, and one of the terms might be null, which then throws a grep
error and breaks the script.