Scripting and Regular Expressions

Prof. Brian D. Davison

Computer Science & Engineering, Lehigh University

Announcements

File Testing

A longer example

As we read through the file, we see: the sh-bang line, comments, local variable declarations. It then tests for the non-existence of a file, and so if true (doesn't exist), it prints an error and exits. We then create a global (environmental) variable, followed by a local numeric variable given the result of an expression that executes the system command date (asking only for the hours) and adding 1 to it. We then make sure the number of hours is not in military (24hr time). A local array of foods is declared, and an integer too. For each person in the list generated by the system command cat on a file (except for root), run the command mail with a message (with variable substitutions) to send. The index variable is updated on each iteration, and is reset if we run through the entire set of food choices.

Globbing

Globbing

The ^ within brackets provides negation.

Regular Expressions

Try changing this slightly to find other words in the dictionary file.

grep

Regular Expressions

Basic Regular Expression Metacharacters

Regular Expression Tags

Extended Regular Expression Metacharacters

Regular Expressions in Emacs

Try running emacs now. Put five lines of Lehigh X where X is the line number. Now use the regex "L.*igh [0-9]" and C-S to see that it matches each one.

Lab exercise (from Quigley)