LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 07-26-2008, 11:04 PM   #1
dtat651
LQ Newbie
 
Registered: Jul 2008
Posts: 4

Rep: Reputation: 0
Question grepping 'how many words have x number of characters'


I have been looking at websites and books and almost everything i can think of and I am sure it is right in front of my face. I am trying to figure out how many 5 letter words are in a specific file.

any help would be much appreciated.
 
Old 07-26-2008, 11:05 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Explain what you think a "word" means.
 
Old 07-26-2008, 11:14 PM   #3
dtat651
LQ Newbie
 
Registered: Jul 2008
Posts: 4

Original Poster
Rep: Reputation: 0
my file is a list of various words.. apples, bananas, grape. I need to know how to pull out grape by grepping all 5 letter words. Does that help?
 
Old 07-26-2008, 11:15 PM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
I know what a word is. I'm trying to get you to define a "word".

Show what you have so far. You mentioned grep...
 
Old 07-26-2008, 11:17 PM   #5
dtat651
LQ Newbie
 
Registered: Jul 2008
Posts: 4

Original Poster
Rep: Reputation: 0
i did this and it worked, but if i need to then add to it... all 6 letter words with at least and 'a' and a 'b' in the word...

grep -cw '.....' file1
 
Old 07-26-2008, 11:20 PM   #6
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
So grep for the letters you need.

Sounds like homework...
 
Old 07-26-2008, 11:23 PM   #7
dtat651
LQ Newbie
 
Registered: Jul 2008
Posts: 4

Original Poster
Rep: Reputation: 0
yep.. I have dug all through the textbook and i have a linux pocket guide and nowhere does it tell me how to put it all together... or maybe it is just late and i need to go to bed and think about it...
 
Old 07-26-2008, 11:23 PM   #8
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Think about it. It will come to you.
 
Old 07-27-2008, 08:15 AM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Not tested:

Extract all 5-letter words:

sed -n '/\<[[:alpha]]\{5\}\>/p' filename > newfilename

Here, "word" is defined as a group of letters (upper or lower case). Look up "bash character classses" for more options.

Similar syntax will work in GREP.

Last edited by pixellany; 07-27-2008 at 08:24 AM.
 
Old 07-27-2008, 08:46 AM   #10
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,832

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
You doing (admitted) homework for people again mate ???.
 
Old 07-27-2008, 10:55 AM   #11
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
don't worry, that's not the answer. so OP has to work out for himself. using regexp to search for exactly 5 words, it will need boundaries.

Last edited by ghostdog74; 07-27-2008 at 11:00 AM.
 
Old 07-27-2008, 12:14 PM   #12
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by syg00 View Post
You doing (admitted) homework for people again mate ???.
I am SORRY!!!!! I missed the part where he acknowledged homework. Besides, we are allowed to help.

Quote:
Originally Posted by ghostdog
don't worry, that's not the answer. so OP has to work out for himself. using regexp to search for exactly 5 words, it will need boundaries.
He's searching for words with 5 letters......
 
Old 07-27-2008, 12:35 PM   #13
RudraB
Member
 
Registered: Mar 2007
Distribution: Fedora
Posts: 262

Rep: Reputation: 23
Quote:
Besides, we are allowed to help.
Should we do everything we are allowed to?
 
Old 07-27-2008, 12:49 PM   #14
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Helping does not mean "giving answers", it means "helping others discover and learn". The point is to encourage students to learn and grow; hinting at where to focus helps in this, whereas giving an answer discourages thought, analysis, and discovery.

Arguably, those that ask for the answers have no interest in learning, and are likely trying to skate by (they'll fail any tough course). I didn't but the "I've tried everything I can think of" nonsense.
 
Old 07-27-2008, 08:51 PM   #15
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by pixellany View Post
He's searching for words with 5 letters......
and counting them.
 
  


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
How do I extract characters from several words on a line? MheAd Linux - Newbie 22 06-23-2008 11:22 PM
Trying to figure out the number of characters in a std::string, using length. RHLinuxGUY Programming 4 05-23-2006 10:39 AM
Search and Replace: Asian Words to English Words ieeestd802 Linux - Software 0 10-27-2004 08:48 PM
Need my keypad ALT-number characters / Redhat 9 quadmore Linux - Newbie 9 07-01-2004 02:38 AM


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