Changes

Jump to: navigation, search

Tutorial9: Regular Expressions

12 bytes added, 12:00, 13 March 2021
INVESTIGATION 3: OTHER COMMANDS USING REGULAR EXPRESSIONS
# Press the '''ESC''' key to make certain you are in '''COMMAND''' mode.<br><br>
# Type the following and press '''ENTER''':<br><span style="color:blue;font-weight:bold;font-family:courier;">/uli101</span><br><br>You should notice the pattern "'''uli101'''" highlighted for ALL occurrences in this text file.<br><br>Let's '''search''' for the '''uli101''' pattern, and '''replace''' it in capitals (i.e '''ULI101''').<br><br>In vi, to issue a command, you need to enter '''LAST LINE''' MODE then issue a command.<br>Let's issue a command from '''LAST LINE''' MODE to search and replace '''uli101''' to '''ULI101'''.<br><br>[[Image:other-re-4.png|thumb|right|500px|In l'''ast line''' MODE in the '''vi''' text editor, issuing a command using regular expressions to convert '''uli101''' to '''ULI101'''.]]
# Making certain that you are '''COMMAND''' MODE in vi,<br>type the following and press '''ENTER''':<br><span style="color:blue;font-weight:bold;font-family:courier;">:%s/uli101/ULI101/g</span><br><br>'''NOTE:''' The letter '''g ''' after the replace regular expression represents "'''global'''" and will replace ALL occurrences of uli101 in the text document (as opposed to replacing the first occurrence for every line).<br><br>
# Type the following (in uppercase letters) and press '''ENTER''':<br><span style="color:blue;font-weight:bold;font-family:courier;">/ULI101</span><br><br>You should notice the pattern "'''ULI101'''" highlighted for ALL occurrences in this text file.<br><br>
# Navigate throughout the text file to confirm that ALL occurrences of '''uli101''' have been <u>replaced</u> with '''ULI101'''.<br><br>
13,420
edits

Navigation menu