Dr. Mark Humphrys

School of Computing. Dublin City University.

Online coding site: Ancient Brain

coders   JavaScript worlds

Search:

Free AI exercises

Search:   See Help on search.

Top hits - matches a folder name:


Medium hits - matches a file name:


Lesser hits - matches in the text of a file:

CA170 - Introduction to Operating Systems
ca170/sample.2.html
<input type=radio name='7' value='1' id='7_1' > <label for='7_1' > <tt> grep "^born" * </tt> </label> <br> 
<input type=radio name='7' value='2' id='7_2' > <label for='7_2' > <tt> grep "^ born" * </tt> </label> <br> 
<input type=radio name='7' value='3' id='7_3' > <label for='7_3' > <tt> grep "^ .born" * </tt> </label> <br> 
<input type=radio name='7' value='4' id='7_4' > <label for='7_4' > <tt> grep "^ .*born" * </tt> </label> <br> 
<input type=radio name='7' value='5' id='7_5' > <label for='7_5' > <tt> grep "^.born" * </tt> </label> <br> 
<input type=radio name='7' value='6' id='7_6' > <label for='7_6' > <tt> grep "born" * </tt> </label> <br> 
<input type=radio name='7' value='7' id='7_7' > <label for='7_7' > <tt> grep "^ *born" * </tt> </label> <br> 
<input type=radio name='12' value='1' id='12_1' > <label for='12_1' > <tt> grep -i King */act* | wc -l </tt> </label> <br> 
<input type=radio name='12' value='2' id='12_2' > <label for='12_2' > <tt> grep -c King */act* | wc -l </tt> </label> <br> 
<input type=radio name='12' value='3' id='12_3' > <label for='12_3' > <tt> grep -ic King */act* | wc -l </tt> </label> <br> 
<input type=radio name='12' value='4' id='12_4' > <label for='12_4' > <tt> grep -ic King */act*   </tt> </label> <br> 
<input type=radio name='12' value='5' id='12_5' > <label for='12_5' > <tt> grep -c King */act*   </tt> </label> <br> 
<input type=radio name='12' value='6' id='12_6' > <label for='12_6' > <tt> grep -i King */act*   </tt> </label> <br> 
<input type=radio name='12' value='7' id='12_7' > <label for='12_7' > <tt> grep King */act*   </tt> </label> <br> 
<input type=radio name='12' value='8' id='12_8' > <label for='12_8' > <tt> grep King */act* | wc -l </tt> </label> <br> 
<li class=question   ca216 ca249 ca651  ca170open     >  What is this script doing?   <p>  <tt>  grep string file > /dev/null </tt
<input type=radio name='25' value='1' id='25_1' > <label for='25_1' > <tt> grep Scotland ../chap*html </tt> </label> <br> 
<input type=radio name='25' value='2' id='25_2' > <label for='25_2' > <tt> grep Scotland chap*html  </tt> </label> <br> 
<input type=radio name='25' value='3' id='25_3' > <label for='25_3' > <tt> grep Scotland \*chap*html  </tt> </label> <br> 
<input type=radio name='25' value='4' id='25_4' > <label for='25_4' > <tt> grep Scotland /*chap*html  </tt> </label> <br> 
<input type=radio name='25' value='5' id='25_5' > <label for='25_5' > <tt> grep Scotland */*/chap*html  </tt> </label> <br> 
<input type=radio name='25' value='6' id='25_6' > <label for='25_6' > <tt> grep Scotland *chap*html  </tt> </label> <br> 
<input type=radio name='25' value='7' id='25_7' > <label for='25_7' > <tt> grep Scotland ./chap*html </tt> </label> <br> 
<input type=radio name='25' value='8' id='25_8' > <label for='25_8' > <tt> grep Scotland */chap*html  </tt> </label> <br> 
CA170 - Introduction to Operating Systems
ca170/sample.html
<li class=question   ca216 ca249 ca651  ca170open     >  What is this script doing?   <p>  <tt>  grep string file > /dev/null </tt
<input type=radio name='2' value='1' id='2_1' > <label for='2_1' > <tt> grep -i King */act*   </tt> </label> <br> 
<input type=radio name='2' value='2' id='2_2' > <label for='2_2' > <tt> grep -c King */act* | wc -l </tt> </label> <br> 
<input type=radio name='2' value='3' id='2_3' > <label for='2_3' > <tt> grep King */act* | wc -l </tt> </label> <br> 
<input type=radio name='2' value='4' id='2_4' > <label for='2_4' > <tt> grep -ic King */act*   </tt> </label> <br> 
<input type=radio name='2' value='5' id='2_5' > <label for='2_5' > <tt> grep -c King */act*   </tt> </label> <br> 
<input type=radio name='2' value='6' id='2_6' > <label for='2_6' > <tt> grep King */act*   </tt> </label> <br> 
<input type=radio name='2' value='7' id='2_7' > <label for='2_7' > <tt> grep -i King */act* | wc -l </tt> </label> <br> 
<input type=radio name='2' value='8' id='2_8' > <label for='2_8' > <tt> grep -ic King */act* | wc -l </tt> </label> <br> 
<input type=radio name='4' value='1' id='4_1' > <label for='4_1' > <tt> grep scotland *html  </tt> </label> <br> 
<input type=radio name='4' value='2' id='4_2' > <label for='4_2' > <tt> grep -i Scotland *html  </tt> </label> <br> 
<input type=radio name='4' value='3' id='4_3' > <label for='4_3' > <tt> grep Scotland *html  </tt> </label> <br> 
<input type=radio name='4' value='4' id='4_4' > <label for='4_4' > <tt> grep -i scotland *html  </tt> </label> <br> 
<input type=radio name='21' value='1' id='21_1' > <label for='21_1' > <tt> grep Scotland ./chap*html </tt> </label> <br> 
<input type=radio name='21' value='2' id='21_2' > <label for='21_2' > <tt> grep Scotland /*chap*html  </tt> </label> <br> 
<input type=radio name='21' value='3' id='21_3' > <label for='21_3' > <tt> grep Scotland chap*html  </tt> </label> <br> 
<input type=radio name='21' value='4' id='21_4' > <label for='21_4' > <tt> grep Scotland *chap*html  </tt> </label> <br> 
<input type=radio name='21' value='5' id='21_5' > <label for='21_5' > <tt> grep Scotland ../chap*html </tt> </label> <br> 
<input type=radio name='21' value='6' id='21_6' > <label for='21_6' > <tt> grep Scotland */*/chap*html  </tt> </label> <br> 
<input type=radio name='21' value='7' id='21_7' > <label for='21_7' > <tt> grep Scotland \*chap*html  </tt> </label> <br> 
<input type=radio name='21' value='8' id='21_8' > <label for='21_8' > <tt> grep Scotland */chap*html  </tt> </label> <br> 
Practical
ca668/practical.html
and this gets into the "grep" command-line call?
Chrome bug - image rotated
chrome.bug.html
<li> <tt>  exiftool file.jpg | grep Orientation </tt>
Help on search
help.search.html
  <li> The search works like <A HREF="http://en.wikipedia.org/wiki/Grep">grep</A>,
<li> The search engine works like grep, because it <I>is </I> grep.
and has   a grep   at the core of it.  
with grep at the core,
grep  at the core.
Dr. Mark Humphrys
index.html
(Written in   PHP with a  grep at the core.)
How to write a search engine in 9 lines of Shell
Notes/CGI/search.engine.html
grep -i "$argument" *html */*html		 |    sed -e 's|&lt;|\&amp;lt;|g'   |   sed -e 's|&gt;|\&amp;gt;|g'   
<li> We pipe the result of grep into an ugly-looking 
there are HTML tags in the results returned by grep.
or get a recursive grep,
grep -i "$argument" $filespec
grep -i "$argument" $filespec
<tt>grep</tt> finds them.
but there is still a grep at the core.
rather than <tt>grep</tt>-ing them on the spot.
But a  <tt>grep</tt> is perfectly  fine for a   site 
Lab - Web
Notes/Internet/lab.web.html
<pre> find / -maxdepth 3  -type d  2> /dev/null  | grep ht  </pre>
Email
Notes/Networks/email.html
e.g. I have programs to "grep" local copy of  my email, 
Lab - 404 PHP handler
Notes/Networks/lab.404.html
<pre> grep -i segment filelist </pre>
<li> Collect the grep output using 
Make the URL safe  for grep 
  We use "." because it means "any character" in grep.
<li> Search each segment. Collect the return code from   grep.
<li> Assume each grep could have multiple matches 
PHP search engine
Notes/Networks/php.search.html
<A HREF="../UNIX/intro.2.html#grep">grep</A>
e.g. Search for <A HREF="https://humphryscomputing.com/search.php?q=grep">grep</A>.
<pre> cd (somedir) ; grep -i (searcharg) */*html </pre>
<li> Collect the grep output in a PHP variable. 
<li> Go  through the   grep  output line by line.
What if  grep returns tens of thousands of lines? <BR>
Pipe grep to <A HREF="../UNIX/shell.utilities.html#head.tail">head</A>, which collects the first  n lines of what is piped into it
<pre> grep string files | head -500 </pre>
<li> The previous will actually <I>terminate  </I>  grep once 500 is reached.
Binary v. Text
Notes/OS/binary.text.html
<H3> grep *doc </H3>
 grep string *doc
that grep returns.
 Q. Can any of these be called from a  DOS script like grep?
<tt> grep "\[\[.*\]\]" * </tt>
Using files
Notes/OS/files.user.html
 sed, grep, ls, cut, etc. 
$ ls -l /bin      | grep '^l'
$ ls -l /usr/bin  | grep '^l'
Processes
Notes/OS/processes.html
<pre> ps -u $USER -f | grep bash </pre>
<pre> ps -Af | grep nano </pre>
humphrys 32374 29859 grep              1
Process Synchronisation and Deadlocks
Notes/OS/synch.html
<tt>grep</tt> &nbsp; is a better example of working 
prog | grep "string"
<tt>grep</tt> &nbsp; doesn't have to wait until 
String searching
Notes/String/string.search.html
<H1> grep </H1>
<A HREF="http://en.wikipedia.org/wiki/Grep">grep</A>
 <A HREF="../Networks/php.search.html"> My search engine based on grep</A>
But how does grep (or  other  string-finding programs)
<h1> What does grep use? </h1>
grep can't use the standard Boyer-Moore algorithm</A>
because grep  allows <A HREF="http://en.wikipedia.org/wiki/Regular_expression">regular expressions</A>
<td>   grep "CO.*STING" </td> 
<td>   grep -i "&lt;img.*src=" </td>
<LI> grep normally  uses a <A HREF="http://en.wikipedia.org/wiki/Finite_state_machine">finite automaton</A>
Disks and file system
Notes/UNIX/disk.html
$ find . | grep ' '
Einstein - cweb
Notes/UNIX/einstein.cweb.html
<PRE> grep Scotland *html </PRE>
by <A HREF="more.html#pipes.etc">piping </a> the output of grep into
<PRE> grep Scotland *html | sed -e "s|Scotland|Finland|g" </PRE>
grep Scotland complete.html
Einstein - Flickr
Notes/UNIX/einstein.flickr.html
<a href="filterbaks.html#egrep">egrep</a>
<pre> egrep 'X|Y' </pre> 
<font color=red><b>[wget command]</b></font> | <font color=red><b>[egrep command]</b></font>
<font color=red><b>[wget command]</b></font> | <font color=red><b>[egrep command]</b></font> | <font color=red><b>[tr command]</b>
Einstein - Search engine
Notes/UNIX/einstein.gweb.html
grep -i "$1" */*html  
grep -i "$1" */*html  
 "&lt;pre>" before the grep
grep -i "$1" */*html  
grep -i "$1" */*html  |  <font color=red><b>[sed command]</b></font>
but   grep output is not clickable. It looks like this:
grep -i "$1" */*html  |  <font color=red><b>[sed command]</b></font>  |  clickable
See  <A HREF="shell.utilities.html#cut.grep.output"> How to use cut to parse grep output</A>. 
A stream of grep hits go into clickable.
So when you upload it to Einstein you need this line  before the grep:
Einstein labs
Notes/UNIX/einstein.html
<li> Now you have your own copy of the works of Shakespeare to practice "grep" and other commands on. 
Einstein - simple Shell scripts
Notes/UNIX/einstein.intro.2.html
<li> grep4.sh
Einstein - simple Shell scripts
Notes/UNIX/einstein.intro.html
  <li> grep2.sh
  <li> grep3.sh
Einstein - stock prices
Notes/UNIX/einstein.stock.2.html
<li> grep for "text-4xl font-bold" <br>
Sample Shell script - filterbaks
Notes/UNIX/filterbaks.html
  ls -al $* | grep -v "%$" | grep -v "~$" | grep -iv "\.bak$"
grep -v means exclude lines that contain the pattern 
$ ls -l *kuwait* | grep -v 'bak'
$ ls -l *kuwait* | grep -v '.bak'
$ ls -l *kuwait* | grep -v '\.bak'
$ ls -l *kuwait* | grep -v '\.bak$'
Make our list of grep's into  a separate file, called say "filterbaks":
       grep -v "%$" | grep -v "~$" | grep -iv "\.bak$"
<H3> <A name="egrep">egrep </A></H3>
We can do this using the "egrep" program,
which can grep for boolean expressions. <BR>
	egrep -iv  "%$|~$|\.bak$" 
Shell functions
Notes/UNIX/functions.html
 du | grep '\.$' | cut -f1 
  ps -Tf | grep -i $1
humphrys 28414 28413  0 12:32:50 pts/5    0:00 grep -i textedit
so we need to strip out killstring itself, and the grep itself.
ps -Tf | grep -i $1 | grep -v $0 | grep -v "grep -i $1" | fn
Introduction to UNIX / Linux (More)
Notes/UNIX/intro.2.html
<H1>  <A name="grep">grep</A></H1>
grep      Search for a string in a file or files
grep (string) (file)
grep (string) *html 
grep -i (string) (file)  Ignore case
grep -v (string) (file)  Return lines that do NOT match 
Find overloaded pages
Notes/UNIX/lab.overloaded.3.html
<li> grep  the file  for   lines   with an embedded image.
<li>  grep again  for embedded images.
<li> Use grep to <I>get  rid of</I> lines with 'http'
<li> Use grep to search for JPEGs only. 
Lab - Shell
Notes/UNIX/lab.shell.html
It then  searches the page (using grep) for the argument.
Wikify a page
Notes/UNIX/lab.wiki.html
<tt> grep '[A-Z][a-z]' </tt>
Lab - xprog
Notes/UNIX/lab.xprog.html
  <LI> <tt> xprog grep </tt> - rejected
How to write a Shell script to download videos from YouTube
Notes/UNIX/lab.youtube.html
 <A HREF="shell.utilities.html#grep">grep </A>
<li> grep for "googlevideo" again.
<li> grep for 
<li> We pipe the above to a grep for the itag we want.
More UNIX
Notes/UNIX/more.html
cat file | grep -i dcu | grep -iv computing | sort
cat file | grep -i student > studentlist
cat file | grep -i staff   > stafflist
grep string file
grep string < file
cat file | grep string
Linux Quiz 3
Notes/UNIX/quiz.3.html
<H3> grep </H3>
Use "grep" to search all "complete.html" and then use "wc".
Use grep of the "complete.html" with a certain option to just list the files that have a  match.
Run a grep and then pipe the result into another grep with a certain option.
As above, see options for grep.
See options for grep.
<H3>  grep of "test suite" </H3>
Linux Quiz B
Notes/UNIX/quiz.b.html
(Use either "grep" or "wc".)
What is wrong with these Shell scripts?
Notes/UNIX/shell.errors.html
for i in 'ps -f | grep textedit' 
More on Shell
Notes/UNIX/shell.more.html
    grep -i "http:.*dcu.ie"          | 
		e.g. grep (switches) (string) file1 ... filen
		e.g. quiet grep: 
		 grep > /dev/null 
		though grep may have -q (quiet) option anyway
	grep ' file        syntax error (why?)
	grep "'" file      surround with quotes and it works
	grep '"' file      to search for the double quote itself
grep string *
# grep does not understand *
# but that's fine because grep does not actually RECEIVE *
# the shell EXPANDS * to a list of files and passes these to grep
# so grep actually receives:
grep string f1 f2 .. fn
Sample Shell programs
Notes/UNIX/shell.sample.html
<li> grep (ignoring case) the argument in all the Shakespeare files
<li> check the return code of grep
Shell utilities
Notes/UNIX/shell.utilities.html
<A NAME="grep">grep</A>
grep                    search for a string
grep string file
(output of prog) | grep string | grep otherstring
  <LI><A HREF="http://en.wikipedia.org/wiki/Grep">grep</A>
<li> <A HREF="http://linux.die.net/man/1/grep">man grep</A>
 <li> grep is <B>Substring-oriented</B> (will match inside a word).
  <tt> grep -w </tt>
<li> grep is <B>Line-oriented</B> (will print whole line that matches).<BR>
Not always good: Hit we want  may spread across multiple lines, so grep  won't  find it.
<li> Recursive grep:
<tt> grep -r string . </tt>
<tt> grep -r --include="*html" string . </tt>
 Use   <A HREF="http://linux.die.net/man/1/egrep">egrep  </A>
egrep -o ".{0,40}string.{0,40}" file
grep "  *"		1 or more spaces
grep "\."           the '.' character itself
grep '\$'	works (searches for the "$" char instead of end-of-line)
grep "\$"	fails (double quote treatment of $ is different to single quote treatment of $)
grep "\\$"	works
<h1><A NAME="cut.grep.output"> How to use cut to parse grep output</A></h1>
In grep output, extract the 1st <B>field</B>, with delimiter ":"
 grep string *html | cut -f1 -d':' 
 grep string *html | cut -f2- -d':' 
grep -i $1 *html |
grep -l '\015' */*html
LC_ALL=C  grep -P "[^\x00-\x7E]" */*html
# if you grep a file with non 7 bit chars you may get a warning like:
grep: file.html: binary file matches
grep string files | head -100 
<pre> grep string files | head -100 </pre>
When head gets the first 100 lines, <I>the pipe closes</I> and grep terminates.  <BR>
As opposed to:  Doing the entire grep and <I>then </I> taking the first 100. <br> 
set | grep -i random
set | grep -i random
Windows batch files
Notes/UNIX/windows.bat.html
grep Ireland r*/*html  
Windows command line
Notes/UNIX/windows.cmd.html
<li> <A HREF="https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find">find </A>  (like grep)