2

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).

2
  • the "remaining lines" in Q, you meant the lines after the "July" line, right? Commented Jul 20, 2013 at 22:09
  • yes, immediately after "July" Commented Jul 23, 2013 at 11:15

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.