Accepting a phrase and counting the number of times that it is repeated in a specific website

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Accepting a phrase and counting the number of times that it is repeated in a specific website
# 1  
Old 12-11-2013
Accepting a phrase and counting the number of times that it is repeated in a specific website

1. The problem statement, all variables and given/known data:


Develop a shell script that accepts a phrase and counts the number of times that it is repeated in a specific website.

Note: Im not sure if it's the whole website, or just a specific page but im guessing its thewhole website.


2. Relevant commands, code, scripts, algorithms:
wget, curl, grep


3. The attempts at a solution (include all code and scripts):
(for now i just did the home page)

Code:
#!/bin/bash
echo "Enter a phrase:"
read phrase
echo "Number of occurences is:"
curl --websiteHere-- | grep "$phrase" | wc -l

Other Ideas:

-wget the whole humber.ca website (so it downloads every page into a .html file) and then grepping that file for the specific phrase.
-downside: this takes way too long (downloading the whole website)

-curling the humber.ca search with the phrase in it (not exactly sure how to do this all in a shell script) so it brings up the pages with the specific phrase for the site and then just grepping and word counting those pages.

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Humber College (North Campus), Toronto, Canada, Alireza M. , 160950: Game 130



Thanks

Last edited by Scott; 12-11-2013 at 11:51 AM.. Reason: Added code tags
# 2  
Old 12-11-2013
So - what's your question? Your snippet should do the job. You might want to consider grep's c option.
# 3  
Old 12-12-2013
I am not sure if this is within the scope of your homework, but will probably have to escape several characters to make your regexp more robust.

Here is an example you can try to see the problem:

Code:
This is the inputfile.
This is a line
A line not containing the word "i s".

Code:
# search="is"
# grep -c "$search" /path/to/inputfile
2

So far, so good. Let us search for full stops. There are 2 lines with a full stop (1 and 3):

Code:
# search="."
# grep -c "$search" /path/to/inputfile
3

Obviously wrong, no? Contemplate the reason why and find out how to correct that.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove duplicate lines which has been repeated 4 times

Remove duplicate lines which has been repeated 4 times attached test.txt below command tried and not getting expect output. for i in `cat test.txt | uniq` do num=`cat test.txt | grep $i | wc -l` echo $i $num done test.txt ... (17 Replies)
Discussion started by: Kalia
17 Replies

2. UNIX for Beginners Questions & Answers

Export lines that have first entry repeated 5 times or above

Dears i want to extract lines only that have first entry repeated 3 times or above , ex data : -bash-3.00$ cat INTCONT-IS.CSV M205-00-106_AMDRN:1-0-6-22,12-662-4833,intContact,2016-11-15 02:32:16,50 M205-00-106_AMDRN:1-0-23-17,12-616-0462,intContact,2016-11-15 02:32:23,50... (5 Replies)
Discussion started by: is2_egypt
5 Replies

3. Shell Programming and Scripting

Counting number of times content in columns occurs in other files

I need to figure out how many times a location (columns 1 and 2) is present within a group of files. I figured using a combination of 'while read' and 'grep' I could count the number of instances but its not working for me. cat file.txt | while read line do grep $line *08-new.txt | wc -l... (6 Replies)
Discussion started by: ncwxpanther
6 Replies

4. Shell Programming and Scripting

How to print the lines which are repeated 3 times in a file?

Hello All, I have a file which has repeated lines. I want to print the lines which are repeated three times. Please help. (3 Replies)
Discussion started by: ailnilanjan
3 Replies

5. UNIX for Dummies Questions & Answers

Extracting column if above certain values and repeated over a number of times continuously

Hi I am new to the forum and would like to ask: i have a file in form with thousands of column id.1 A01 A01 A68 A68 id.2 A5 A5 A3 A3 1001 0 0 0.136 0.136 1002 0 0 0.262 0.183 1003 0 0 0.662 0.662 1004 0 0 ... (9 Replies)
Discussion started by: newbeeuk
9 Replies

6. UNIX for Dummies Questions & Answers

To get the total of how many times the pattern is repeated.

Hi, I need the total of how many times the pattern is being repeated in a particular file. I tried with grep as below, but no go. grep -c best sample Contents of Sample file: ----------------------- This is the best site I have never come across. The best one indeed. Very best... (8 Replies)
Discussion started by: venkatesht
8 Replies

7. Shell Programming and Scripting

Print a word specific number of times

Hi All, I wanted to know if there is a shell command to print a word n number of times The Input File is : Cat 4 Bat 3 Zall 1 Kite 2 Output File required is : Cat Cat Cat Cat Bat Bat Bat Zall Kite (4 Replies)
Discussion started by: sam_2921
4 Replies

8. UNIX for Dummies Questions & Answers

Counting the number of times a character appears

I am looking for a bash command that counts the number of times a character appears in a file. For example "I am a newbie, trying to learn shell script". Then the command counts the number of e and gives them as 4. Also I want one that counts the number of times a character in a string is replaced.... (2 Replies)
Discussion started by: #moveon
2 Replies

9. UNIX for Dummies Questions & Answers

how many times does this repeated sequence exist

need a script to determine daily how many times does the below repeated sequence exist in a log file, and if it shows failure to connect in the same file 200 PORT Command successful. 150 Opening BINARY mode data connection for rgr016.daily.0305. 226 Transfer complete. local: rgr016.daily.0306... (3 Replies)
Discussion started by: lichento
3 Replies

10. Shell Programming and Scripting

Counting Number of times a File is accessed

Hi, I need to count the number of times a script is accessed from within the script. Is it possible ? Example: I have a script called lo.sh and i execute the script for the first time, then the counter variable declared inside the lo.sh should increment by 1. For every execution the... (1 Reply)
Discussion started by: pathanjalireddy
1 Replies
Login or Register to Ask a Question