LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Searching Text Files for Large Numbers (https://www.linuxquestions.org/questions/linux-newbie-8/searching-text-files-for-large-numbers-853481/)

will.flanagan 12-31-2010 03:59 PM

Searching Text Files for Large Numbers
 
Hi Linux Gurus,

I am looking for a way to search for large numbers in text files and print the nearby lines.

For example if I had a text file like:

Event: 11
blah: 3
blah: 41 bleh: 19
Event: 2
blah: 31
blah: 4 bleh: 91
Event: 3
blah: 3
blah: 4 bleh: 9

I want to pick out lines with numbers above 50 and the previous 2 lines. In this case I would want to pick out:

Event: 2
blah: 31
blah: 4 bleh: 91

This doesn't seem like it should be hard, but I am sure having a hard time figuring out a way. Any help would be greatly appreciated.

Thanks in advance,
Will

business_kid 12-31-2010 04:17 PM

use egrep, which is grep, but searching for regular expressions. to form a regular expression read man regex. Off the yop of my head, you're looking for something like

egrep -C5 -e 'nnn' <file to search> |less

You can also steer it to use the Perl regex rules (better organised than Posix) and covered by man perlre. Bury your head for a day.


All times are GMT -5. The time now is 03:57 AM.