LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-14-2011, 06:43 AM   #1
k.raj
LQ Newbie
 
Registered: Nov 2011
Posts: 5

Rep: Reputation: Disabled
vowels grep command


Hey.!
I have a file f3.txt
It contains --
The American Revolution.
This is the best solution to the problem
PanAmerica Capital Group
the american people
ddd
United States of America
america
the brown fox jumped over a lazy dog.
Creative thinking
I want to write a command using grep to list all the lines that contain words having exactly 1 vowel.
??
 
Old 11-14-2011, 06:47 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
It seems that this has to be homework, and we are not here to do your work for you. We can help with specific queries, but we are not going to spoon feed you answers. Thanks.
 
2 members found this post helpful.
Old 11-14-2011, 06:49 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
What have you tried so far?
 
Old 11-14-2011, 07:02 AM   #4
k.raj
LQ Newbie
 
Registered: Nov 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by catkin View Post
What have you tried so far?
i tried using
grep -iw ".\?[aeiou]\?" f3.txt
the problem that i'm having is that when i type in the above command it searches for a specific number of letters in a word.
I want it to work for any word(having any number of letters) that fits my condition.
 
Old 11-14-2011, 08:18 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
The meaning of ".\?[aeiou]\?" is:
  1. 0 or 1 of any character
  2. 0 or 1 of any vowel
You want a pattern that matches:
  1. Any number of non-vowels
  2. 1 vowel
  3. Any number of non-vowels
That would match:
Code:
The American Revolution.
This is the best solution to the problem
the american people
United States of America
the brown fox jumped over a lazy dog.
 
Old 11-14-2011, 01:21 PM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Quote:
Originally Posted by catkin View Post
You want a pattern that matches:
  1. Any number of non-vowels
  2. 1 vowel
  3. Any number of non-vowels
I'd like to make a slight amendment to this list:
  1. Start of a word
  2. Any number of non-vowels
  3. 1 vowel
  4. Any number of non-vowels
  5. End of a word

The regex required for this is not difficult. You should also read through grep's man and info pages for details on its usage and features.
 
1 members found this post helpful.
Old 11-14-2011, 03:22 PM   #7
k.raj
LQ Newbie
 
Registered: Nov 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
thanks i got it..!
 
Old 11-14-2011, 03:23 PM   #8
k.raj
LQ Newbie
 
Registered: Nov 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
I agree ,Chris.
i just wanted some hint or suggestion on how to approach the question and not to spoon feed me.
Thanks anyways.
 
Old 11-14-2011, 03:24 PM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by David the H. View Post
I'd like to make a slight amendment to this list
I believe grep's -w option (which the OP is using) addresses your concern.
 
Old 11-14-2011, 03:28 PM   #10
k.raj
LQ Newbie
 
Registered: Nov 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by catkin View Post
I believe grep's -w option (which the OP is using) addresses your concern.
Yea.! .. Also, instead of ? wildcard, * wildcard should be used.
 
Old 11-14-2011, 10:52 PM   #11
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
If you have solved it, would you like to post your solution in case anybody has a similar question?

Threads can be marked SOLVED via the Thread Tools menu.
 
Old 11-15-2011, 11:55 AM   #12
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Oddly enough, I get different results when I use word boundries and -w.

(I hope it's ok to post what I have now)

Code:
$ egrep '\<[^aeiou]*[aeiou][^aeiou]*\>' file
The American Revolution.
This is the best solution to the problem
the american people
United States of America
the brown fox jumped over a lazy dog.


$ echo "$text" | egrep -iw '[^aeiou]*[aeiou][^aeiou]*'
The American Revolution.
This is the best solution to the problem
the american people
United States of America
the brown fox jumped over a lazy dog.
I cannot figure out why it's not matching every single-vowel word in the second case.
 
Old 11-15-2011, 12:06 PM   #13
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
How do you know which words it is matching?
 
Old 11-15-2011, 02:00 PM   #14
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
With the --color option, sorry. I have it set through the GREP_OPTIONS shell variable, and didn't think to include it when posting here.
 
Old 11-16-2011, 01:45 AM   #15
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Both forms of the egrep command give the same output here:
Code:
c@CW8:/tmp$ egrep --color=auto '\<[^aeiou]*[aeiou][^aeiou]*\>' f3.txt 
[snip]
c@CW8:/tmp$ egrep --color=auto -iw '\<[^aeiou]*[aeiou][^aeiou]*\>' f3.txt 
[snip]
c@CW8:/tmp$ env | grep GREP
c@CW8:/tmp$ grep --version
GNU grep 2.5.4
[snip]
 
  


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
PHP5 - Zend Framework->translate: capital vowels with acents disappear j-ray Programming 0 07-25-2011 09:22 AM
grep command john83reuben Linux - Newbie 9 12-09-2009 12:21 PM
How to pass the result of a command to another command (like grep) desb01 Programming 4 06-25-2009 01:09 PM
Help me in Grep Command + cd command in single line JeiPrakash Linux - Newbie 3 05-27-2008 05:16 AM
Marked vowels and Opera 8.5 gbj SUSE / openSUSE 6 09-22-2005 02:10 AM


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