Search

Using grep to search in reverse

Grep ,which is used to search for a string or a pattern in the input,always starts searching from the beginning of the file.

But if we wanted to start the search from the back that is from the last line, then We can use grep in combination with tac.

tac displays the content of a file from last line to first line , if this is piped to grep it will be able to search in the reverse.

For example if we have a file with the name file1

file1



If we want to search for the string distros which is at the end we can use.


No comments:

Post a Comment