The UNIX and Linux Forums  


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
Counting occurence of a particular character on each line hey_mak UNIX for Dummies Questions & Answers 4 06-26-2008 06:56 AM
counting the occurence of particular characters Audra UNIX for Dummies Questions & Answers 2 03-28-2008 10:01 AM
search& count for the occurence of a word skoppana UNIX for Dummies Questions & Answers 1 11-09-2007 05:07 PM
Delete all occurence of a word in one shot namishtiwari Shell Programming and Scripting 6 08-24-2007 09:41 AM
Counting occurence of a coma dbrundrett Shell Programming and Scripting 3 01-22-2004 05:40 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-30-2009
pranabrana's Avatar
pranabrana pranabrana is offline
Registered User
  
 

Join Date: Jun 2008
Location: Bangalore
Posts: 19
counting the occurence of a word

In a file I have to count a particular word. like i need apache how many times.

I tried this

$ tr "\011" "\012\012"<foo1 | tr -cd "[a-zA-z\012]" |sort\uniq -c


but I got result like this

32 apache
18 dns
12 doctor


Please sugest me
  #2 (permalink)  
Old 06-30-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 748
If all you want is the count for apache then you could do:

Code:
$ tr "\011" "\012\012"<foo1 | tr -cd "[a-zA-z\012]" | grep "^apache$" | wc -l

Update I had assumed the tr bits were working but they aren't...

Here is something that works:

Code:
$ tr "\011\040" "\012\012"<foo1 | grep -ic "^apache$"


Last edited by TonyFullerMalv; 06-30-2009 at 05:04 PM.. Reason: Workinh version!
  #3 (permalink)  
Old 06-30-2009
pranabrana's Avatar
pranabrana pranabrana is offline
Registered User
  
 

Join Date: Jun 2008
Location: Bangalore
Posts: 19
Quote:
Originally Posted by TonyFullerMalv View Post
If all you want is the count for apache then you could do:

Code:
$ tr "\011" "\012\012"<foo1 | tr -cd "[a-zA-z\012]" | grep "^apache$" | wc -l


Thanks !!! any simpler way ?
  #4 (permalink)  
Old 06-30-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Is 'apache' the same as 'apaches' and the same as apache's or 'apache,'?
  #5 (permalink)  
Old 07-06-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 748
Quote:
Originally Posted by vgersh99 View Post
Is 'apache' the same as 'apaches' and the same as apache's or 'apache,'?
Not if you do what I did:

Code:
grep "^apache$"

Which is looking for apache with a start of line at the beginning and an end of line at the end!
Reply

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 11:38 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