LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-24-2014, 06:03 PM   #1
mia_tech
Member
 
Registered: Dec 2007
Location: FL, USA
Distribution: CentOS 5.3, Ubuntu 9.04
Posts: 229

Rep: Reputation: 16
need help creating a webpage with bashscript


I have a directory containing documentation like: php, mysql and others. So I'm working on a bash script that basically runs
Code:
grep -ir searchpattern directory
and I'm getting the output and putting it into a webpage. but I'm having trouble formatting the output because the browser open local files in the for of
Code:
file:///path.html
I'm not able to find a way to append file:///path to the result from grep

Code:
searchTerm=$2	#search term eg: parameters, variables, etc..
directory=$1	#directory to be searched eg: php, mysql, bash, etc
prefix="file://$(pwd)"	#prefix to be added to every result in order to open in browser
results=""	#storing result from search


#1-check for right num of parameters
if [ $# -ne 2 ]; then
	echo "USAGE $(basename $0) directory searchterm"
	exit 1
fi

webpage() {
	
	cat << END
		<!doctype html>
		<html>
		<head><title>SearchDocs</title></head>
		<body>
		$results
		</body>
		</html>
END
}


#2-loop through parameters and and search
results=$(grep -ir $searchTerm $directory | cut -d: -f1 | sort -u)

for line in $results
do
	results="${results}$prefix/$line"
done

webpage $results > searchdoc.html
I would eventually pass the result as links <a> tags to the page... so if anyone has an idea how to do it I appreciate it

Last edited by mia_tech; 04-24-2014 at 06:04 PM.
 
Old 04-24-2014, 07:18 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Look at awk

or gawk,

awk can be confusing, since a few versions of it
Figure out which you have and run...

If awk is not an option, grep + sed

Perl and python also options
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Doc for creating a simple webpage satimis Linux - General 14 04-12-2011 06:32 AM
[SOLVED] Grep error in Bashscript tuxianD Linux - Newbie 8 07-14-2010 08:50 AM
noob: creating script to make webpage/img Xeratul Programming 2 05-26-2007 07:06 AM
Creating a webpage for the first time metallica1973 Linux - Software 2 03-09-2006 11:09 PM
how do I use a bashscript code? (for torsmo) fatblueduck Linux - Software 9 07-29-2005 04:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:47 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration