LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-21-2009, 10:02 AM   #1
maginotjr
Member
 
Registered: Aug 2004
Location: BR - Floripa
Distribution: Ubuntu 9.10 - 2.6.x.x
Posts: 661

Rep: Reputation: 35
Question 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
 
Old 01-21-2009, 11:51 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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?
 
Old 01-21-2009, 09:29 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
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
 
Old 01-23-2009, 05:04 AM   #4
maginotjr
Member
 
Registered: Aug 2004
Location: BR - Floripa
Distribution: Ubuntu 9.10 - 2.6.x.x
Posts: 661

Original Poster
Rep: Reputation: 35
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you make search ...search a string in a link....a url...a web address aus9 LQ Suggestions & Feedback 4 04-16-2008 09:37 AM
Perl regex - search and replace duplicate chars PAix Programming 10 12-18-2007 03:19 AM
MySQL: search for pluralized keywords using RegEx? MicahCarrick Programming 1 09-26-2006 08:50 PM
Search for text inside files alaios Linux - Newbie 7 03-12-2006 09:20 AM
Regex search in files with python smokybobo Programming 0 11-08-2003 06:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration