LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-02-2015, 10:39 AM   #1
Nexusfactor
Member
 
Registered: Jan 2015
Distribution: Ubuntu
Posts: 50

Rep: Reputation: Disabled
Bash Script to Search a Webpage


I've Googled my problem, and it's getting more confusing.

I want to write a bash script that will search this page for a specific string and echo if it's found. For example, if I wanted to search for the string "Game Developer", which exists on the page, it would echo "Found Game Developer!"

I'm not sure where to even begin. I'm using Lubuntu 14.04.2 LTS

This best I came up with is this:

wget -q -O- http://www.centennialcollege.ca/prog.../job-postings/ | grep -c "Game Developer"


Is this the correct way of doing it?

How do I get it to print the number of times the string appears?

Last edited by Nexusfactor; 07-02-2015 at 10:57 AM.
 
Old 07-02-2015, 11:25 AM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
grep -c does count the 'hits',so I start with that...
Try this:
Code:
#!/bin/bash
HITCOUNT=$(wget -q -O- http://www.centennialcollege.ca/programs-courses/centres-institutes/applied-research-and-innovation/for-students/job-postings/ | grep -c "Game Developer")
if [[ "$HITCOUNT" = 0 ]]  ; then echo "No Hits Found..." ; else echo Found "$HITCOUNT" hit\(s\) ; fi

Last edited by Habitual; 07-02-2015 at 11:27 AM.
 
1 members found this post helpful.
Old 07-02-2015, 12:03 PM   #3
Nexusfactor
Member
 
Registered: Jan 2015
Distribution: Ubuntu
Posts: 50

Original Poster
Rep: Reputation: Disabled
Thanks, I like this approach much better!
 
Old 07-02-2015, 12:53 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
You are very welcome.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run bash script from link on webpage? inkscape Linux - General 18 05-29-2013 09:09 AM
bash script search file skarychinezeguie Linux - Newbie 3 12-19-2010 09:01 PM
Search and Replace in bash script daemoneye Other *NIX 1 04-08-2009 01:24 AM
Bash script to search through directories. mcdrr Programming 5 05-11-2007 05:41 PM
search function (bash script) LYK Programming 2 05-27-2004 10:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration