LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Using Regex to make a search inside Less ?? (https://www.linuxquestions.org/questions/programming-9/using-regex-to-make-a-search-inside-less-698885/)

maginotjr 01-21-2009 10:02 AM

Using Regex to make a search inside Less ??
 
Hi,

I'm posting this question here because of the Regexp, if Im in the wrong place please let me know.

The question is simples, can I search inside Less using a RegExp ?
If the answer is yes, how can I make a backsearch for to word to be matched in the same line but in aleatory place with Regexp?

Thanks !


Example: find the word hotmail and john in:
John accessed this page: hotmail.com

pixellany 01-21-2009 11:51 AM

A quick scan of "man less" does not suggest that you can use normal Regexes, but there are some codes that look useful.

Have you tried it?

For real searching with real Regexes, why not GREP, SED, or other common utilities?

ntubski 01-21-2009 09:29 PM

less does support regexp's:

Quote:

Originally Posted by man less
/pattern
Search forward in the file for the N-th line containing the pattern. N defaults to 1.
The pattern is a regular expression, as recognized by the regular expression library
supplied by your system.

?pattern will search backward.

I don't think regexps are that great at doing the particular kind of search you want though, (John.*hotmail|hotmail.*John) is probably the best you can do (if you know John goes before hotmail you can use just the first half, of course). With grep you can use more than one regexp like this:
Code:

grep John file | grep hotmail

maginotjr 01-23-2009 05:04 AM

This file Im reading is a Log file of about 4gb, some weird problem made the syslog not to rotate the files and now I had to find some information requested by the company high board... using grep is normaly my first choice but in this case trying to quick the process I used the less and ? / to find what I want, of course I didnt hope to get the answer before the time I had to give the information to the board, but this doubt sticked in my head and I came here to ask maybe for a future know how...

btw, this logrotate problem will be my next thread, very strange thing, in old days just syslog was responsible for logging and stuff now Im having many problems trying to figure out who do what in the logging business lol

but already was of good help your answers.
thansk
[ ]'s


All times are GMT -5. The time now is 09:00 PM.