Download The unix programming environment
Transcript
96
The unix programming environment
#
#
the shell interprets these!
open (FILE,"regex_test");
$regex = $ARGV[$#ARGV];
print "Looking for $ARGV[$#ARGV] in file...\n";
while (<FILE>)
{
if (/$regex/)
{
print;
}
}
#
# Test like this:
#
# regex '.*'
# regex '.'
#
# regex '[a-z]'
# regex '[^a-z]'
#
# regex '[A-Za-z]'
# regex '[0-9]'
# regex '#.*'
# regex '^#.*'
# regex ';\n'
#
- prints every line (matches everything)
- all lines except those containing only blanks
(. doesn't match ws/white-space)
- matches any line containing lowercase
- matches any line containg something which is
not lowercase a-z
- matches any line containing letters of any kind
- match any line containing numbers
- line containing a hash symbol followed by anything
- line starting with hash symbol (first char)
- match line ending in a semi-colon
Try running this program with the test data on the following le which is called `regex_test'
in the example program.
# A line beginning with a hash symbol
JUST UPPERCASE LETTERS
just lowercase letters
Letters and numbers 123456
123456
A line ending with a semi-colon;