finding no of counts the words occured


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers finding no of counts the words occured
# 1  
Old 09-09-2007
Data word by word search between two files

hi,
cud u help me to find this.

i hav 2 files.
file1 has data as "ARUN
ARUN is from Australia
Arun likes America etc..
ARUN ARUN "
file2 has "ARUN
Australia
America"

i need to find no of counts the words of file2 has occured in file1.

Last edited by arunsubbhian; 09-09-2007 at 02:47 AM..
# 2  
Old 09-09-2007
Code:
for i in `cat file2`
do
   count=`grep $i file1 | wc -l`
   echo "Word $i from file2 occured $count time in file1"
done

kamitsin
# 3  
Old 09-09-2007
Data Hi Ther

but it is not workin if ther r two arun in same line or any work that has multiple occurance in the same word
# 4  
Old 09-09-2007
Code:
for i in `cat cc1`
do
   count=`grep $i cc | xargs -n1 | grep $i | wc -l`
   echo "Word $i from cc1 occured $count time in cc"
done

Cheers,
K
kamitsin
# 5  
Old 09-09-2007
MySQL Yup it worked...

But i tried it using sed command as...

count=` sed -s "s/ /\n/g" $1 |grep -i $i | wc -w`

cud u xplain diff bw these. n say which is optimised n hw Smilie
# 6  
Old 09-09-2007
With Awk:

Code:
awk 'NR==FNR{x[tolower($1)];next}{
	for(i=1;i<=NF;i++)
		if(tolower($i) in x)
			y[tolower($i)]++}END{
	for(i in y)
		print i,y[i]
}' file2 file1

With nawk or /usr/xpg4/bin/awk on Solaris.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding non-existing words in a list of files in a directory and its sub-directories

Hi All, I have a list of words (these are actually a list of database table names separated by comma). Now, I want to find only the non-existing list of words in the *.java files of current directory and/or its sub-directories. Sample list of words:... (8 Replies)
Discussion started by: Bhanu Dhulipudi
8 Replies

2. Shell Programming and Scripting

Count events occured in the same second in awk

Hello to all in forum, I need to count how many events happens within each second for 01 Aug 2013.(because in the sample appears records for 01 Aug and 02 Aug). The output for the input below should be: Desired Output: --> 2 Records --> 1 Record --> 3 Records Input: DEBUG... (5 Replies)
Discussion started by: Ophiuchus
5 Replies

3. UNIX for Dummies Questions & Answers

Grep.Need help with finding the words which start at [A-K] letters in thesecond column of the table

Hi buddies ! I need some help with one grep command :) I have this table: 1 Petras Pavardenis 1980 5 08 Linas Bajoriunas 1970 10 3 Saulius Matikaitis 1982 2 5 Mindaugas Stulgis 1990... (1 Reply)
Discussion started by: vaidastf
1 Replies

4. Shell Programming and Scripting

Finding my lost file by searching for words in it

Got a question for you guys...I am searching through a public directory (that has tons of files) trying to find a file that I was working on a longggggg time ago. I can't remember what it is called, but I do remember the content. It should contains words like this: Joe Pulvo botnet zeus... (5 Replies)
Discussion started by: statichazard
5 Replies

5. Shell Programming and Scripting

Finding consecutive same words in a file

Hi All, I tried this but I am having trouble formulating this: I have a file that looks like this (this is a sample file words can be different): network router frame network router computer card host computer card One can see that in this file "network" and "router" occur... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

6. Shell Programming and Scripting

finding and removing 2 identical consecutive words in a text

i want to write a shell script that correct a text file.for example if i have the input file: "john has has 2 apples anne has 3 oranges oranges" i want that the output file be like this: "john has 2 apples anne has 3 oranges" i've tried to read line by line from input text file into array... (11 Replies)
Discussion started by: cocostaec
11 Replies

7. Shell Programming and Scripting

Finding the number of unique words in a file

find the number of unique words in a file using sort com- mand. (7 Replies)
Discussion started by: abhikamune
7 Replies

8. Shell Programming and Scripting

Finding the most frequently occurring set of words

Hi guys, I have a file with a list of phoneme for words, it looks like this: AILS EY1 L Z AIMLESSLY EY1 M L AH0 S L IY0 AIMONE EY1 M OW2 N AIMS EY1 M Z AINGE EY1 NG AINGE(2) EY1 N JH AINLEY EY1 N L IY0 AINSLIE EY1 N Z L IY0 AIR EH1 R AIRBAGS EH1 R B AE2 G Z and I need to... (5 Replies)
Discussion started by: Andrew9191
5 Replies

9. Shell Programming and Scripting

counts the number of distinct words

I'm looking to write a sample shell script that counts the number of distinct words in a text file given as Argument. Remark: White space characters are spaces, tabs, form feeds, and new lines. JUST with this commands tr, sort, grep. wc. Thanks. (14 Replies)
Discussion started by: Net-Man
14 Replies

10. Shell Programming and Scripting

how to find capital letter names in a file without finding words at start of sentence

Hi, I want to be able to list all the names in a file which begin with a capital letter, but I don't want it to list words that begin a new sentence. Is there any way round this? Thanks for your help. (1 Reply)
Discussion started by: kev269
1 Replies
Login or Register to Ask a Question