Search code examples
linuxcommand-linegreptail

Grep for a string in file without using pipe


I want to grep for a word in a file in the last n lines without using the pipe.

grep <string> filename

enables to search the filename for a string. But, I want to search for a string in the last N lines of the file. Any command to search for that without using the pipe?


Solution

  • Use Process Substitution to search string only in last 5 lines:

    grep string <(tail -n 5 filename)