GREP - Generalized Regular Expression Processor - What's it all about?

Grep

[DOWNLOAD GREPZIP.ZIP NOW] (70k)
Grep is a simple but powerful tool that has almost infinite uses. Anytime you are looking for any text, grep comes in use. Grep searches for a word or regular expression and outputs every line containing it to the screen.

Grep And Offline Cartoon Voice-Finding

If you want to use the cartoon voices database on your own harddrive, simply save it with your web-browser. If you want, change the filename to just "voices" instead of "voices.htm". (Personally, I called the file voices before I put it on the web and had to add the .htm extension)

Then, go to the directory where you saved it. Once you are at the DOS command line, you have all the power:

Say you want all the Gargoyles voices. All you have to do is type:

grep gargoyles voices.htm
...and you will get a line-by-line output of all the Gargoyles voices.

Say you want all the Frank Welker voices. All you have to do is type:

grep frank\ welker voices.htm
...and you will get a line-by-line output of all of Frank Welker's voice credits. If you are wondering what the backslash does, the answer is this: The backslash makes the computer LOOK for a SPACE. Otherwise grep would be looking for "frank" in a file called "welker", and we wouldn't want that.

Regular Expressions / Advanced Grep

A regular expression is a way of specifying a very general string.
The following regular expression symbols are treated specially:

   ^  start of line             $  end of line
   .  any character             \  quote next character
   *  match zero or more        +  match one or more

   [aeiou0-9]   match a, e, i, o, u, and 0 thru 9
   [^aeiou0-9]  match anything but a, e, i, o, u, and 0 thru 9
Say you wanted to search for all John Smiths. Then you'd need to type:
grep john\ smith voices.htm
Say you wanted to find the cartoon voices for "The Big Dog" and "The Little Dog". Then you'd need to type:
grep the\ .*\ dog voices.htm
Of course, this would also match up with any line that had "The" in it followed by "dog", such as this line:
Imogene Coca: Garfield:guest[The Fairy Dogmother]
So maybe you decide to get a little more specific. You know that "Big" starts with "B" and that "Little" starts with "L", so you can narrow it down to just those words that begin with those letters by typing:
grep the\ [bl].*\ dog voices.htm
This will narrow things down even more. Thus the power of grep.

So what about grepping for these special characters themselves? Maybe you want to look for any $ signs-- But $ is a special character used for regular expressions. So if you wanted to look for a $, you'd have to actually type \$ instead. If you wanted to look for \, you'd have to actually type \\ instead. (The backslach is an industry standard for special characters both in regular expressions and in C programming, as well as many UNIX shells.)

Piping To Grep

You can pipe the output of a program to grep the same way you can with any program. Say you are looking for a file with the word "the" in the filename, but you don't know if it's at the beginning (the*.*), at the end (*the.*), or maybe it's even the extension (*.the). So what do you do? Try the directory command with all of these different options? I would say just grep for "the" in your directory! But how do you do this? Simple:

dir | grep the
I even have an alias called "dg" (directory grep) so I can just type:
dg the

You could create this command with DOS by creating a BAT file called DG.BAT and putting it in your PATH (click here for an explanation of what a path is). By the way, GREP should be in your path as well. Anyway, the DG.BAT should look like this:
----TOP OF FILE----
@echo off
dir | grep %1 %2 %3 %4 %5 %6 %7 %8 %9
----END OF FILE----

Now instead of saying "dir *.com" you can say "dg com". This may not seem useful, but if you have filename descriptions you can grep for those. You can also grep for dates, like "dg -96", which would look for all files from the year 1996. Nifty, huh?





Please email me with interesting convo: ClintJCL@gmail.com
You are visitor number [an error occurred while processing this directive] (since 3/15/97).
Go back to Clint's Page On Offline Cartoon Voice Reading.
Go back to Clint's Cartoon Voices Page.
Go back to Clint's Main Page.