Saturday, May 4, 2024
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 6056  / 3 Years ago, sun, october 17, 2021, 1:56:07

Is there something which can be used to search and highlight terms in terminal output? I need to search for "Error" after running make.


More From » gnome-terminal

 Answers
4

Using grep and its variations



Usually grep is used for plain searching. It would work like this:



make 2&>1 | grep Error


Or if there was a lot of output and you wanted to use a pager:



make 2>&1 | grep Error | less


However, if you want to see all the content, and not just the lines that match your search, you could install the ack-grep package, and then do this:



make 2>&1 | ack-grep --passthru Error 


And if that generates a lot of output and you want to use a pager, you need a bit more syntax to preserve the color:



make 2>&1 | ack-grep --passthru Error --color | less -R


In all the examples I included 2>&1 which merges the STDERR and STDOUT output streams. Otherwise, you would only get STDOUT, which might not include all the errors.



One more variation is just to go straight into a pager and search within that:



make 2>&1 | less


One way to search in less is by typing / to enter a search term. See man less for more searching options.



Using terminal menu



Using the Search menu or a keyboard short-cut Shift+Ctrl+F


[#33218] Sunday, October 17, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
olfdit

Total Points: 118
Total Questions: 98
Total Answers: 97

Location: Honduras
Member since Fri, Nov 25, 2022
1 Year ago
;