How to grep a string after a specified line number?
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.