Reputation: 493
I already have a log say file.txt.
I will like to check in Bash, if a string (July) exists in the log and if so, check the remaining lines in the log for another string (foobar).
Upvotes: 2
Views: 302
Reputation: 195289
if you have awk available, an awk oneliner could do it for you:
awk '/July/{f=1} f&&/foobar/{print "Found foobar after July!";exit}' file
if no July
or no foobar after July
, the command prints nothing. of course you could make an if-else, to let it print "not found" or something.
Upvotes: 5