LinuxQuestions.org
Help answer threads with 0 replies.
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-05-2011, 09:19 PM   #1
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,484

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
grep with pattern


Input: each line in the file is six characters.

Desired output: all lines which have "as" or "ek" in positions 3 and 4.

grep '..[as|ek]..' doesn't do the trick.

grep '..[a|e][s|k]..' also fails.

Please advise.

Daniel B. Martin
 
Old 12-05-2011, 09:24 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
The problem are the square brackets. You're defining a character
class, overthinking the pattern.

Code:
egrep '^..(as|ek)..'
should do.
 
Old 12-05-2011, 10:13 PM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,484

Original Poster
Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
Excellent. Thank you!

egrep '^..(as|ek)..'
This is the answer.

Would egrep '^..(as|ek)'
also be correct?

Daniel B. Martin
 
Old 12-05-2011, 11:16 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by danielbmartin View Post
Excellent. Thank you!

egrep '^..(as|ek)..'
This is the answer.

Would egrep '^..(as|ek)'
also be correct?

Daniel B. Martin

If the file-format is well described, and all lines do indeed
have the six characters, and this is not an additional requirement
for you to check, yes, absolutely.


Cheers,
Tink
 
  


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
grep till second pattern rattlesnakejoe Programming 1 11-22-2009 09:09 AM
[SOLVED]matching a pattern with grep kdelover Programming 2 09-18-2009 07:07 AM
grep exact pattern kapila Linux - Newbie 11 08-06-2009 03:58 AM
grep lines between occurances of a pattern ksri07091983 Solaris / OpenSolaris 5 04-26-2009 07:14 AM
using grep when the pattern contains a ! farmerjoe Programming 9 03-16-2005 12:04 AM


All times are GMT -5. The time now is 04:57 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