UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 18th, 2006, 01:57 PM
kev269 kev269 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 37 kev269 User rank is Private First Class (20 - 50 Reputation Level)kev269 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 18 h 34 m 51 sec
Reputation Power: 4
Sentence count

Hi,

The following code counts the number of times a specific word appears in a file by separating each word onto a new line and then using grep to count how many lines contain that word.

Is there a way to change this so that it counts the number of sentences?

tr ' \t' '\n\n' < text | grep -c "$word"

Thanks.

Reply With Quote
  #2  
Old March 19th, 2006, 05:13 AM
Ehlanna's Avatar
Ehlanna Ehlanna is offline
Not a clue what to put ...
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: in front of this keyboard
Posts: 815 Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 5 h 36 m 20 sec
Reputation Power: 243
First off, define what ends a sentence. That could be, but is not limited to: .!?" - then just look for them (and count!).

Reply With Quote
  #3  
Old March 19th, 2006, 10:32 AM
kev269 kev269 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 37 kev269 User rank is Private First Class (20 - 50 Reputation Level)kev269 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 18 h 34 m 51 sec
Reputation Power: 4
thanks for the reply. I want it to count the following '.!?'. I tried this, but I think my syntax is wrong. sorry im a newbie

tr -dc '.' < text | wc -c

Thanks again.

Reply With Quote
  #4  
Old March 20th, 2006, 08:05 AM
stanleypane's Avatar
stanleypane stanleypane is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Baltimore, MD
Posts: 208 stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 7 h 4 m 19 sec
Reputation Power: 21
You could try using the fold command to seperate each character onto a seperate line. Then you could count the characters that end a sentence (.!?) using grep and wc together.
Code:
fold -w 1 | grep "[\.\!\?]" | wc -l

This won't, however, take into account any periods, exclamations or question marks placed mid sentence, such as an abbreviation (Mr., Ph.D., etc.)

Reply With Quote
  #5  
Old March 20th, 2006, 12:46 PM
Ehlanna's Avatar
Ehlanna Ehlanna is offline
Not a clue what to put ...
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: in front of this keyboard
Posts: 815 Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 5 h 36 m 20 sec
Reputation Power: 243
Not at all simple, is it? A lot would depend on just how critical the accuracy is. If it is important that the value returned/printed is accurate as possible you are hoing to need to parse the input carefully, keeping track of context - are we in a quote and thus may not need to cound a '.', or was the previous character a '.' too; maybe implying we are in mid-ellipsis (the ... 'character').

Knowing *nix systems there is probably am existing base utility that will, with the flick of a switch, do exactly what you want!

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Sentence count


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT