I'm looking through some large log files (1-10 GB) and have been running into trouble using the standard less search functions (/). Searching for strings takes several minutes to find a match.

I heard that using fgrep was quicker but I don't really know how I would use this from within less, I'm also open to other suggestions. I have no particular need for regex functionality; I'm just matching strings (regex would be nice but if I can forego it for significant speed improvements that would be fine).

I have very little information about where a particular entry would be, and I don't want to trim the file in any way because once I find a match I will need to see the information in its vicinity (so grep | less isn't really useful for me).

Any quick fixes here?


You dont need a regex to use grep. To solve your problem I probably would use grep as follows:

-i is case insensitive -C is lines of context before and after (example shows 10 which should give you 21 lines for each match)

grep -i -C 10 "text" <file> | less
  • Thanks, that's certainly the best solution I've heard so far. – quant May 12 '14 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.