Computing.Net > Forums > Unix > Help! need a script

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.

Help! need a script

Reply to Message Icon

Name: Naseem Rahman
Date: November 8, 2000 at 11:56:40 Pacific
Comment:

I am trying to write a script that will
take a log file as an input and search
for a word and count the number of times
it occur. Please Help



Sponsored Link
Ads by Google

Response Number 1
Name: Robert Smith
Date: November 10, 2000 at 12:53:12 Pacific
Reply:

#!/usr/bin/sh
##
###
####
#####
occur=`grep -c -i -e $1 $2`
print "The Word $1 Appears $occur Times in $2"
## Remove the -i to make the search case sensitive. Parameter $1 is the word you are searching for, parameter to is the log file you want to search.

example "script" warning /var/adm/syslog/mail.log

Hope this helps!

Robert Smith
Systems Administrator
Biomatrix Inc.


0

Response Number 2
Name: naseem rahman
Date: November 16, 2000 at 15:13:22 Pacific
Reply:

Robert thanks for your help.
Just wondering If I want to search for a phrase do I just use "" ?


0

Response Number 3
Name: Mark Stanbrook
Date: November 21, 2000 at 08:36:44 Pacific
Reply:

In general I tend to use double quotes to enclose phrases though in certain cases single quotes are preferred. The O'Reilly UNIX in a Nutshell book has a little section on this - second edition page 44.

You can do
"Word word2" to search for: Word word2
'Word "word2"' to search for: Word "word2"
"Word \"word2\"" also for: Word "word2"
"`date +%Y`" to search for the current year ie 2000 (as of writing!)
Mark


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Help! need a script

need a script which runs infinately www.computing.net/answers/unix/need-a-script-which-runs-infinately/8230.html

Need a unix script to ping servers www.computing.net/answers/unix/need-a-unix-script-to-ping-servers-/5090.html

unix newbie help need with script www.computing.net/answers/unix/unix-newbie-help-need-with-script/5942.html