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
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