Changes

Jump to: navigation, search

Tutorial9: Regular Expressions

455 bytes added, 10:20, 7 July 2020
INVESTIGATION 2: EXTENDED REGULAR EXPRESSIONS
# 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 two or more occurrences of the word "the":<br><span style="color:blue;font-weight:bold;font-family:courier;">egrep -i "(the){2,}" numbers2.dat | more</span><br><br>You should not see any output due to the fact that a space should be included at the end of the word "the". Usually words are separated by spaces; therefore, there were no matches since there were not occurrences of "thethe" as opposed to "the the"<br><br>
# Reissue the previous command including a space in brackets:<br><span style="color:blue;font-weight:bold;font-family:courier;">egrep -i "(the ){2,}" numbers2.dat | more</span><br><br>The or symbol | can be used within the grouping regular expression symbol to allow matching of additional groups of characters. Again, it is important to follow the character groupings with the space character<br><br># Issue the following linux command to search for 2 or more occurrences of the word "the" or the word "and":<br><span style="color:blue;font-weight:bold;font-family:courier;">egrep -i "(the |and ){2,}" numbers2.dat | more</span><br><br>
=INVESTIGATION 3: OTHER COMMANDS THAT USE REGULAR EXPRESSIONS =
13,420
edits

Navigation menu