Changes

Jump to: navigation, search

Tutorial9: Regular Expressions

2 bytes added, 10:39, 28 February 2021
INVESTIGATION 2: EXTENDED REGULAR EXPRESSIONS
# Issue the following Linux pipeline command using '''egrep''' instead of ''grep'':<br><span style="color:blue;font-weight:bold;font-family:courier;">egrep "^[+-]{0,1}[0-9]{1,}$" numbers2.dat | tee better-number1.txt</span><br><br>You should have noticed that the command worked correctly this time because you used the '''egrep''' command.<br><br>'''NOTE:''' In extended regular expressions, the '''?''' symbol can be used to represent the '''{0,1}''' repetition symbols<br>and the '''+''' symbol can be used to represent the '''{1,}''' repetition symbols<br><br>
# Issue the following Linux pipeline command using the repetition shortcuts <span style="font-weight:bold;font-family:courier;">"+"</span> and <span style="font-weight:bold;font-family:courier;">"?"</span>:<br><span style="color:blue;font-weight:bold;font-family:courier;">egrep "^[+-]?[0-9]+$" numbers2.dat | tee better-number2.txt</span><br><br>You should have seen the same results, but the extended regular expression required less typing.<br><br>
# Issue the following Linux pipeline command to display '''signed''', '''unsigned''', '''whole''', and '''decimal''' numbers:<br><span style="color:blue;font-weight:bold;font-family:courier;">egrep "^[+-]{0,1}[0-9]{1,}[.]{0,1}[0-9]*$" numbers2.dat | tee better-number3.txt</span><br><br>Were all signed and unsigned intergers and decimal numbers displaydisplayed?<br><br>
# Issue the command to check that you correctly issued<br>those ''Linux pipeline commands'' using the '''tee''' command to create those text files: <br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts/week9-check-2</span><br><br>If you encounter errors, then view the feedback to make corrections, and then re-run the checking script.<br>If you receive a congratulation message that there are no errors, then proceed with this tutorial.<br><br>You can also use extended regular expression symbols for '''grouping'''.<br>For example, you can search for repetitions of GROUPS of characters (like a word)<br>as opposed to just a single character or a GROUP of numbers as opposed to a single digit.<br><br>
# Issue the following linux pipeline command to download another data file called '''words.dat''':<br><span style="color:blue;font-weight:bold;font-family:courier;">wget <nowiki>https://ict.senecacollege.ca/~murray.saul/uli101/words.dat</nowiki></span><br><br>
13,420
edits

Navigation menu