Can less search multiple patterns?

QuestionsQuestions8 SkillsProDec, 25 2025
0169

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:

  1. Open your file: less server_log.txt
  2. Press / to start a search.
  3. 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 -i while inside less before you search, or start less with the -i flag: less -i server_log.txt.
  • Highlighting: less will highlight all matches for both terms.
  • Navigation: Just like a single search, press n to go to the next occurrence (of either word) and N to 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!

0 Comments

no data
Be the first to share your comment!