Computing.Net > Forums > Linux > Occurance of multiple words in file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Occurance of multiple words in file

Reply to Message Icon

Name: Kaleem
Date: April 23, 2003 at 02:32:18 Pacific
OS: Red Hat Linux 6.1/8.0
CPU/Ram: PIII
Comment:

Scenario :
==========

There is an enrolment data file containing details of a centre and the subject codes with other details which can be given as :

2002/sem2/abc1234/abc1 : 2345/E/XX
2002/sem1/abc1235/xyz1 : 4556/D/RR
2002/summer/abc1235/dec1 : 2350/E/RR
2002/sem2/abc1234/abc1 : 2345/E/RR

-------------
N.B. :

Chennai = XX
Bombay = RR

The data file is entered using pico editor manually. We assume the data file exists.

I want to know how could a user using the either (bash/shell) script can find the occurance of words like abc1235 occuring in a file eg. words like XX, RR and to count them and to print them.

The user is to enter the command on the command line prompt like

./occur.sh enrol.dat 2002 sem2 abc1234 abc1235

and the output must be :

Code Chennai Bombay Total
==== ======= ====== =====
abc1234 1 1 2
abc1235 0 2 2

I did using grep command to cut the value, but I was able to cut only one value but how to count the occurance of multiple words in a file. Any help from the Linux gurus/Linux Community will be appreciated.

Thanks,

Regards,
Kaleem.



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: April 23, 2003 at 05:56:51 Pacific
Reply:

See if

grep 'abc1234' infile | grep -c XX

will give you the numbers you are looking for.


0
Reply to Message Icon

Related Posts

See More


Ethernet Card Not Initial... intel 845 chipset sound d...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: Occurance of multiple words in file

RedHat9 upgrade, X won't start www.computing.net/answers/linux/redhat9-upgrade-x-wont-start/22880.html

Best way to organize files in Linux www.computing.net/answers/linux/best-way-to-organize-files-in-linux/28797.html

error in file system check www.computing.net/answers/linux/error-in-file-system-check/27956.html