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
count occurences of specific character in the file superprogrammer HP-UX 9 04-09-2008 11:05 AM
Count the number of occurence of perticular word from file rinku Shell Programming and Scripting 40 08-10-2007 07:33 PM
grep and count no of occurences in every line of a file srikanthgr1 Shell Programming and Scripting 12 04-20-2007 09:16 AM
How to count no of occurences of a character in a string in UNIX kamesh83 UNIX for Advanced & Expert Users 11 03-17-2006 02:39 PM
word count showing wrong number of lines tselvanin UNIX for Dummies Questions & Answers 3 01-06-2004 11:33 PM

Reply
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 Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #8 (permalink)  
Old 11-30-2007
$antaclau$'s Avatar
$antaclau$ $antaclau$ is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 4
Hi,

I am not much of an expert. But maybe we could something primitive like the following:




#!/bin/sh
#
# Usage: kountword "200" filename
#
srchWord="$1"
srchFilename="$2"

ctr=0
while read strLine
do
for eachWord in `echo $strLine`
do
if [ "$eachWord" = "$srchWord" ]
then
ctr=`expr $ctr + 1`
fi
done
done < srchFilename
printf "\n\ntheFile contains %s : %d times\n\n" $srchWord $ctr



#-----

I've not tried it but I beleive this should work

Thanks
$anta


Last edited by $antaclau$; 11-30-2007 at 08:32 PM..
  #9 (permalink)  
Old 06-25-2009
roussine roussine is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 29
Quote:
Originally Posted by Yogesh Sawant View Post
using Perl: run this script as :
Code:
$ perl search_word.pl 200 filename
Cheers everyone!
I have a particularly similar need to count occurrences of words. The detail is that the words are many and are contained in ahother file.

Perl experts, can u pls tell if it's possible to modify this script such that it accepts a file with strings to count in another file?

and example string file would be:

roweiurwoiur
gfdkgjdlfkgjh
wiruyweoiry

i.e. one string per line.

The file to search in contains these strings delimited by non-word-constituent characters, not blanks.

thank u much in advance!

PS I tried this script with my data - it works! although finding strings one by one seems not feasible..
Sponsored Links
Reply

Bookmarks

Tags
grep, perl, perl shift, shift, shift perl

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 06:36 AM.


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