Changes

Jump to: navigation, search

Tutorial9: Regular Expressions

1 byte added, 15:20, 6 July 2020
INVESTIGATION 1: SIMPLE & COMPLEX REGULAR EXPRESSIONS
# Issue the following command to match strings begin and end with a number with nothing or anything inbetween:<br><span style="color:blue;font-weight:bold;font-family:courier;">grep "^[0-9].*[0-9]$" textfile1.txt | more</span><br><br>Using simultaneous anchors combined with the .* symbol(s) can help you to refine your search patterns of strings.<br><br>
# Issue the following linux pipeline command to display strings that begin with a capital letter, ends with a number, and contains a capital X somewhere inbetween:<br><span style="color:blue;font-weight:bold;font-family:courier;">grep "^[A-Z].*X.*[0-9]$" textfile1.txt | more</span><br><br>Let's look at another series of examples involving '''filtering''' with numbers so only strings containing valid numbers are displayed.<br><br>
# First, issue the following linux command to download another data file called numbersnumbers1.dat:<br><span style="color:blue;font-weight:bold;font-family:courier;">wget <nowiki>https://ict.senecacollege.ca/~murray.saul/uli101/numbersnumbers1.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 that begin with a capital letter, ends with a number, and contains a capital X somewhere inbetween:<br><span style="color:blue;font-weight:bold;font-family:courier;">grep "^[A-Z].*X.*[0-9]$" textfile1numbers1.txt dat | more</span><br><br>Let's look at another
=INVESTIGATION 2: EXTENDED REGULAR EXPRESSIONS =
13,420
edits

Navigation menu