Changes

Jump to: navigation, search

Tutorial9: Regular Expressions

5 bytes removed, 09:12, 9 March 2021
INVESTIGATION 1: SIMPLE & COMPLEX REGULAR EXPRESSIONS
# Issue the following linux Linux command to '''download''' a text file to your '''home''' directory:<br><span style="color:blue;font-weight:bold;font-family:courier;">wget <nowiki>https://ict.senecacollege.ca/~murray.saul/uli101/textfile1.txt</nowiki></span><br><br>
# Issue the '''ls''' Linux command to confirm that the text file was downloaded.<br><br>
# View the contents of the '''textfile1.txt''' file using the '''more''' command and quickly view the contents of this file.<br><br>Although there are several Linux commands that use regular expressions,<br>we will only be using the '''grep''' command for this investigation.<br><br>[[Image:regexps-1.png|thumb|right|250px|Output of '''grep''' command matching simple regular expression "'''the'''" (only lowercase). Notice the pattern matches larger words like "'''their'''" or "'''them'''".]]
#Issue the following Linux command to match the pattern "'''the'''" within '''textfile1.txt''':<br><span style="color:blue;font-weight:bold;font-family:courier;">grep "the" textfile1.txt</span><br><br>Take a few moments to view the output and observe the matched pattern.<br><br>
# Now, issue the grep Linux command with the <span style="font-weight:bold;font-family:courier;">-i</span> option to ignore case sensitively:<br><span style="color:blue;font-weight:bold;font-family:courier;">grep -i "the" textfile1.txt</span><br><br>What do you notice is different when issuing this command?<br><br>You will notice that the pattern "'''the'''" is matched including larger words like "'''them'''" and "'''their'''".<br>You can issue the '''grep''' command with the -w option to only match the pattern as a '''word'''.<br><br>
13,420
edits

Navigation menu