The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
egrep DNAx86 Shell Programming and Scripting 7 01-18-2008 08:59 AM
Egrep cheat sheet anywhere? Looking for meaning of egrep -c leelm UNIX for Dummies Questions & Answers 2 01-11-2008 03:37 PM
egrep syntax question DKNUCKLES Shell Programming and Scripting 1 11-18-2007 04:46 PM
Egrep Help FuzzyNips UNIX for Dummies Questions & Answers 2 11-10-2004 04:25 PM
egrep -f tine UNIX for Dummies Questions & Answers 2 06-25-2003 10:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-19-2006
rohitv rohitv is offline
Registered User
  
 

Join Date: May 2006
Posts: 7
question on egrep

Hi
I am trying to use this command:
egrep '^a{2,6}$' testexpr4D

to retreive lines with 2,3,4,5, or 6 a's in a file .
The file testexpr4D has entries like:
a
aa
aaa
aaaa
aaaaa
aaaaaa
123456
ABCDEF

I was expecting to see 5 lines in the output but nothing happens.
Can anyone help please?
Thanks
Rohit
  #2 (permalink)  
Old 05-19-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Code:
egrep '^a\{2,6\}$' testexpr4D
  #3 (permalink)  
Old 05-19-2006
rohitv rohitv is offline
Registered User
  
 

Join Date: May 2006
Posts: 7
question on egrep

Hi Shreenmotor,
That doesn't work either !

Thanks
Rohit
  #4 (permalink)  
Old 05-19-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
This works:
Code:
 egrep '^(a)(a)?' filename
test:
Code:
kcsdev:/home/jmcnama> cat filename
a
aa
aaa
aaaa
aaaaa
aaaaaa
123456
ABCDEF



kcsdev:/home/jmcnama> egrep '^(a)(a)?' filename
a
aa
aaa
aaaa
aaaaa
aaaaaa
Note:
Code:
 egrep '^(a)+$' filename
is closer to correct - correct being 'find a line of any non-zero length that has only the letter a'

Last edited by jim mcnamara; 05-19-2006 at 03:36 PM..
  #5 (permalink)  
Old 05-22-2006
rohitv rohitv is offline
Registered User
  
 

Join Date: May 2006
Posts: 7
question on egrep

Jim,
Your solution fetches all the a's in a file . I need to fetch the lines with
2 to 6 a's in a line
Rohit
  #6 (permalink)  
Old 05-22-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by shereenmotor
Code:
egrep '^a\{2,6\}$' testexpr4D
shereenmotor, that solution is pretty close, but no cigar !

You are mixing the syntax's of sed and [e]grep.

If it were sed, it would be

Code:
sed -n -e "/^a\{2,6\}$/p" filename
If it were grep it would be

Code:
egrep '^a{2,6}$' filename
  #7 (permalink)  
Old 05-22-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
put one 'a'

Put a single a before the mentioned pattern. You should get your result.
egrep '^a(a)+$' filename
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0