Q:

How to grep a string after a specified line number?

I have a large text file, I want to see the lines containing "time spent" in this text file, I use:
grep -in "time spent" myfile.txt

But I'm interested only in the lines after 50000. In the output I want to see lines after 50000 and that contain "time spent". Is there a way to do this?

A:

You can tail it, then grep:
tail -n +50000 myfile.txt | grep -in "time spent"

A:

Alternatively you can use sed.
sed can be used to mimic grep like this:
sed -n 's/pattern/&/p'
By default sed prints every line even if no substitution occurs. The combinations of -n and /p makes sed print only the lines where a substitution has occured. Finally, we replace pattern by & which means replace pattern by itself. Result: we just mimicked grep.
Now sed can take a range of lines on which to act. In your case:
sed -n '50000,$s/time spent/&/p' myfile.txt
The format to specify the range is as follow: start,end
We just instruct sed to work from line 50000 to $ which means last line.

A:

Answer for grepping between any 2 line numbers:
Using sed and grep:

sed -n '1,50000p' someFile | grep < your_string >

