School of Computing. Dublin City University.
The following is a fully working search engine for your web pages in 9 lines of Shell:
#!/bin/sh echo "Content-type: text/html" echo echo '<html> <head> <title> Search results </title> </head> <body>' argument=`echo "$QUERY_STRING" | sed "s|q=||"` cd /users/homes/me/public_html echo '<pre>' grep -i "$argument" *html */*html | sed -e 's|<|\<|g' | sed -e 's|>|\>|g' echo '</pre>'
The command is tricky to write because "&" has special meaning to sed and must be escaped.
Since each search will be using the same file list, it would be more efficient to pre-build the list once, and cache it in a file, and then:cd /users/homes/me/public_html filespec=`find . -type f -name "*html" | tr '\n' ' '` grep -i "$argument" $filespec
(I hope you realise that a heavy-duty search engine would go further and pre-index all the files in advance, rather than grep-ing them on the spot. But simple grep is alright for a personal website.)read filespec < filelist.txt grep -i "$argument" $filespec
But the principle is that in Shell you can rustle up
a quick search engine for your personal pages,
or any subset of them, in a few lines.
e.g. My search engine in about 55 lines of Shell (with a C++ input pre-processor for security) has most of the above enhancements.