Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-31-2010, 03:59 PM   #1
LQ Newbie
Registered: Apr 2009
Posts: 15

Rep: Reputation: 0
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,
Old 12-31-2010, 04:17 PM   #2
LQ Guru
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 8,271

Rep: Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Copying large numbers of files dman65 Linux - General 8 02-26-2009 07:32 PM
Best way to organize large numbers of files. dman65 Linux - General 4 03-12-2008 07:42 PM
LXer: Using 'ls' and 'xargs' to manage large numbers of files LXer Syndicated Linux News 0 02-15-2007 06:16 AM
changing SOAs in named with large numbers of zone files untoldone Linux - Networking 3 08-17-2004 02:35 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:54 PM.

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