LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 12-31-2010, 04:59 PM   #1
will.flanagan
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,
Will
 
Old 12-31-2010, 05:17 PM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 7,565

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


Reply


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


All times are GMT -5. The time now is 11:52 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration