plz help me urgent....


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers plz help me urgent....
# 1  
Old 09-24-2008
plz help me urgent....

i want shell script program for counting the no of times the given input word is occured in the given input file.i am unable to do this .i got some of output with awk but i need it completely with shell script program



i am waiting for the solution
# 2  
Old 09-24-2008
Post what you have attempted so far - someone may assist.....

and a gentle comment - when you have a title like "urgent" a lot of people will assume this is homework and you have a deadline - homework questions are frowned upon.....

better to have your title as a more descriptive staement of the actula problem - e.g. "trying to count occurences of words in inpout file in awk" or somesuch
# 3  
Old 09-24-2008
Here is the command
grep -o "wordpattern" filename|wc -l
# 4  
Old 09-24-2008
Hammer & Screwdriver Perhaps this will work for you

The following is my sample file
Code:
> cat file.txt
the angry person went to the store
to buy a new operating system as he saw
at the theatre a new and improved system
to handle all of the mundane tasks of
his boring job.

Now, after putting each word on its own line, grep for "the"
Code:
> tr " " "\n" <file.txt | grep "the" 
the
the
the
theatre
the

Notice the word "theatre" was selected. To correct for the, I use the -w option with grep as follows:
Code:
> tr " " "\n" <file.txt | grep -w "the" 
the
the
the
the

And finally, output a count
Code:
> tr " " "\n" <file.txt | grep -w "the" | wc -l
4

# 5  
Old 09-24-2008
Quote:
tr " " "\n" <file.txt | grep -w "the" | wc -l
That's Useless Use of wc -l

" -c " option of grep would do that

Code:
tr " " "\n" <file.txt | grep -cw "the"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

2. AIX

Need help..Urgent plz

Hi All, For listing large files i am using the following command find /XYZ/ -xdev -size +100000 |xargs ls -l |sort -nr -k 5..And my question is i am getting more number of files with this, so not able to copy those, how can I get those all in page by page , so that I can able to copy those... (4 Replies)
Discussion started by: adminaix55
4 Replies

3. Shell Programming and Scripting

error in shell script while returning values-- urgent issue plz help.

Hi, I have initailized a varaible EBID as typeset Long EBID=0 i am calculating value of EBID using certian formula as below: (( CURR_EBID= ($BANDINDEX << 27) | ($CURR_FREQ << 16) | ($CURR_CELLID << 4) | $CURR_SECTOR_VALUE )) return $CURR_EBID The output is as below: + (( CURR_EBID=... (6 Replies)
Discussion started by: kasanur
6 Replies

4. Shell Programming and Scripting

Clarify doubt ... plz Urgent

Hi friends, I am new to UNIX. I going to transfer files using SFTP. I am writing a script and using mget . If i am using mget * means, if all the files and their sub directories are transferred or not? If suppose , the local system dose not have the sub directory then what will... (1 Reply)
Discussion started by: punitha
1 Replies

5. Programming

plz help me to solve this socekt progm..urgent...

MY client and server need to achieve the following requirements: 1.1. program for client needs to take two arguments that specify the name of server and the port that it is trying to connect to. Your program for server needs to take an argument that specifies the port that it is listening to. ... (6 Replies)
Discussion started by: saiful_911
6 Replies

6. Shell Programming and Scripting

help in writing awk script, plz urgent

I have a file like this I have to I have input file this , I want to give the out put in the below input file (NARAYANA 1 ENDING AT (100, 16383) ,NARAYANA 2 ENDING AT (100, 32766) ,NARAYANA 3 ENDING AT (100, 49149) ,NARAYANA 4 ENDING AT (100, 65535) ,NARAYANA 5... (8 Replies)
Discussion started by: LAKSHMI NARAYAN
8 Replies

7. Shell Programming and Scripting

plz solve this one : URGENT

Hi! How to use awk command and set command in a shell script? Suppose I have to fetch data from a file and change one data with another one.Say data is ABCD.Now I have to change C with X .How do I solve this one? (2 Replies)
Discussion started by: joyita bagchi
2 Replies

8. UNIX for Dummies Questions & Answers

find command - Urgent Plz.

Hi, In my current directory, i have the following files: x1.dat x2.dat.gz x3.dat I want to use the find command and display only files which has *.dat and NOT *.gz extension files. Please help me out. Thanks, Kris Kart. (2 Replies)
Discussion started by: Kris_Kart_101
2 Replies

9. UNIX for Dummies Questions & Answers

urgent plz

guys i have sun solaries 8 under intel .. i added a new D-LINK ethernet and i need to see if the computer define it or not .. so i need to make reconfiguraion .. what was the command ... for reconfiguration ??? thanks alot (3 Replies)
Discussion started by: tamemi
3 Replies

10. UNIX for Dummies Questions & Answers

plz Help How should I configure cc compiler output file plz help???

i.e configuration of C compiler :confused: (4 Replies)
Discussion started by: atiato
4 Replies
Login or Register to Ask a Question