David542
David542

Reputation: 110183

Grep from end of file

Is there a way to start the grep search from the end of the file instead of the beginning? Here is from the beginning --

$ grep -irn 'Qyt13_pUFjQ' ./

The information that I am looking for is close to the end of the file, but takes a few minutes to get all the way there from the start.

Upvotes: 14

Views: 21434

Answers (2)

Petr Skocik
Petr Skocik

Reputation: 60068

You can use tac to read the file line by line from the end to the beginning, then possibly switch it around again with another tac if you need to.

Upvotes: 19

mti2935
mti2935

Reputation: 12027

You can do tail -n xxxx file.txt | grep ... to pipe the last xxxx lines of the file through grep.

Upvotes: 5

Related Questions