That's a great question! While the standard search in less (using /) usually focuses on one pattern at a time, you can actually achieve multiple pattern searching using Regular Expressions.
Since less supports extended regular expressions, you can search for multiple terms simultaneously using the OR pipe operator (|).
How to do it:
- Open your file:
less server_log.txt - Press
/to start a search. - Type your patterns separated by
\|(the backslash escapes the pipe).
For example, to find lines containing either "ERROR" or "WARNING":
/ERROR\|WARNING
Tips for Multiple Searches:
- Case Insensitivity: If you want to search regardless of upper or lower case, type
-iwhile insidelessbefore you search, or startlesswith the-iflag:less -i server_log.txt. - Highlighting:
lesswill highlight all matches for both terms. - Navigation: Just like a single search, press
nto go to the next occurrence (of either word) andNto go to the previous one.
In your current lab setup, try opening the file and searching for two different events at once to see how it works!