LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-04-2013, 07:39 AM   #1
linnoa
LQ Newbie
 
Registered: Nov 2013
Posts: 1

Rep: Reputation: Disabled
Using egrep to match patterns


Hi there,

I am hoping to get some help with this exercise; I need to make regular expressions for collections with egrep to solve it.

Given are a lot of lines with numbers and spaces
ig: 222 266222 266
6444 44555 577
To be a part of the collection, the sum of the numbers two places before the space and to places after have to be 8.
222 266222 266 -> 2+6=8
I have to do this for these combinations: 2 and 6, 5 and 3

So far I have this: egrep '(2. .6|6. .2|3. .5|5. .3)'
But with this expression, as long as one space matches the expression it becomes part of the collection, so I can still end up with 7. .7 at another space for example.
I need this expression to match for every possible space.

Any ideas?

Thanks in advance
Sara
 
Old 11-04-2013, 09:04 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,129

Rep: Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272
probably you need to negate: use egrep to drop lines where pattern does not match
 
  


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
[SOLVED] using sed to inclusively match multiple patterns in one line..?? WetFroggy Programming 5 09-11-2013 02:31 PM
[SOLVED] script to match patterns on files and echo on the same line rebelbuttmunch Linux - Newbie 3 11-22-2011 06:46 AM
get files that match ALL patterns (using grep?) vigilandy Linux - General 5 06-09-2010 05:18 AM
egrep for only words(exact match) msgforsunil Linux - Newbie 4 04-14-2010 06:27 AM
Python scriptutil for patterns that don't match donnied Programming 8 03-05-2009 01:06 PM


All times are GMT -5. The time now is 08:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration