Include -A flag to add lines after match and -B flag to add lines before grep match -A 3 #display match line and 3 after lines grep match -B 2 #display match line and 2 lines before
Just filter your output with: grep -v "excluded_pattern" Example to get all not txt files in current directory. ls | grep -v .txt