13,420
edits
Changes
→INVESTIGATION 1: SIMPLE & COMPLEX REGULAR EXPRESSIONS
# First, issue the following linux command to download another data file called numbers1.dat:<br><span style="color:blue;font-weight:bold;font-family:courier;">wget <nowiki>https://ict.senecacollege.ca/~murray.saul/uli101/numbers1.dat</nowiki></span><br><br>
# View the contents of the '''numbers.dat''' file using the '''more''' command and quickly view the contents of this file. You should notice valid and invalid numbers contained in this file. When finished, exit the more command.<br><br>
# Issue the following linux command to display strings only whole numbers:<br><span style="color:blue;font-weight:bold;font-family:courier;">grep "^[0-9]*$" numbers1.dat | more</span><br><br>You may have noticed that begin with the command does not entirely work. You may notice an empty line (which is NOT a whole number). This occurs since the * regular expression symbol represents ZERO or MORE occurrences of a capital letter, ends number. You can use an additional numeric character class with the * regular expression symbol to search for one or more occurrences of a number, and contains a capital X somewhere inbetween.<br><br># Issue the following linux command to display only whole numbers:<br><span style="color:blue;font-weight:bold;font-family:courier;">grep "^[A0-Z9][0-9]*$" numbers1.dat | more</span><br><br>You should see that this works.<br><br># Issue the following linux command to display whole positive or negative integers:<br><span style="color:blue;font-weight:bold;font-family:courier;">grep "^[+-][0-9][0-9]*X$" numbers1.dat | more</span><br><br>What did you notice?<br><br># Issue the following linux command to display only whole numbers (with or without a positive or negative sign):<br><span style="color:blue;font-weight:bold;font-family:courier;">grep "^[+-]*[0-9]*$" numbers1.dat | more</span><br><br>Let's look at another
=INVESTIGATION 2: EXTENDED REGULAR EXPRESSIONS =