School of Computing. Dublin City University.
Online coding site: Ancient Brain
coders JavaScript worlds
<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>
<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>
<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.
grep -i "$argument" *html */*html | sed -e 's|<|\&lt;|g' | sed -e 's|>|\&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
<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
<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.
<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>
sed, grep, ls, cut, etc. $ ls -l /bin | grep '^l' $ ls -l /usr/bin | grep '^l'
<pre> ps -u $USER -f | grep bash </pre> <pre> ps -Af | grep nano </pre> humphrys 32374 29859 grep 1
<tt>grep</tt> is a better example of working prog | grep "string" <tt>grep</tt> doesn't have to wait until
<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 "<img.*src=" </td> <LI> grep normally uses a <A HREF="http://en.wikipedia.org/wiki/Finite_state_machine">finite automaton</A>
<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
<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>
grep -i "$1" */*html grep -i "$1" */*html "<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:
<li> Now you have your own copy of the works of Shakespeare to practice "grep" and other commands on.
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$"
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
<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
<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.
<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.
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
<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>
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
<li> grep (ignoring case) the argument in all the Shakespeare files <li> check the return code of grep
<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
<li> <A HREF="https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find">find </A> (like grep)