Changes

Jump to: navigation, search

Tutorial9: Regular Expressions

31 bytes added, 07:09, 31 January 2021
INVESTIGATION 1: SIMPLE & COMPLEX REGULAR EXPRESSIONS
# Issue the following linux command to display only whole numbers:<br><span style="color:blue;font-weight:bold;font-family:courier;">grep "^[0-9]*$" numbers1.dat | tee faulty.txt | more</span><br><br>You may have noticed that 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 number. You can use an additional numeric character class with the * regular expression symbol to search for one or more occurrences of a number.<br><br>
# Issue the following linux command to display only whole numbers:<br><span style="color:blue;font-weight:bold;font-family:courier;">grep "^[0-9][0-9]*$" numbers1.dat | tee whole.txt | 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]*$" numbers1.dat | tee signed.txt | 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 | tee all.txt | more</span><br><br>
Proceed to Investigation 2.
13,420
edits

Navigation menu