Changes

Jump to: navigation, search

Tutorial9: Regular Expressions

1,256 bytes added, 08:30, 7 July 2020
INVESTIGATION 2: EXTENDED REGULAR EXPRESSIONS
# Issue the following linux command to download another data file called numbers2.dat:<br><span style="color:blue;font-weight:bold;font-family:courier;">wget <nowiki>https://ict.senecacollege.ca/~murray.saul/uli101/numbers2.dat</nowiki></span><br><br>
# View the contents of the '''numbers2.dat''' file using the '''more''' command and quickly view the contents of this file.<br>You should notice valid and more invalid numbers contained in this file. When finished, exit the more command.<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][0-9]*$" numbers2.dat | more</span><br><br>You should notice multiple + or - signs are appearing as well. This occurs since you are searching or one or MORE occurrences of a + or - sign.<br><br>Using '''extended regular expression''' symbols can solve this problem.<br><br> In # Issue the next investigationfollowing 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.1}[0-9]{1,}$" numbers2.dat | more</span><br><br>NOTE: most likely, you will there were NO results. This is due to the fact that the grep command was NOT issued correctly to use extended regular expression symbols. You would need to issue either '''grep -E''' (or more simply) issue the '''egrep''' command.The egrep command works with all regular expression symbols, and should be used in the future instead of the older grep command.<br><br># Issue the corrected command:<br><span style="color:blue;font-weight:bold;font-family:courier;">egrep "^[+-]{0,1}[0-9]{1,}$" numbers2.dat | more</span><br><br>Did the command work this time?<br><br>
=INVESTIGATION 3: OTHER COMMANDS THAT USE REGULAR EXPRESSIONS =
13,420
edits

Navigation menu