Changes

Jump to: navigation, search

Tutorial9: Regular Expressions

No change in size, 21:39, 6 March 2021
INVESTIGATION 3: OTHER COMMANDS THAT USE REGULAR EXPRESSIONS
#Let's learn how to perform a simple '''search and replace''' within the '''vi''' utility by using regular expressions.<br>Issue the following Linux command to edit the '''large-file.txt''' file:<br><span style="color:blue;font-weight:bold;font-family:courier;">vi large-file.txt</span><br><br>Let's first perform a simple search within this text file.<br><br>
# 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 move to the '''first occurrence''' of the pattern: '''uli101'''.<br><br>Let's search for the '''uli101''' pattern, but 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|300px400px|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, type the following and press ENTER:<br><span style="color:blue;font-weight:bold;font-family:courier;">:%s/uli101/ULI101/g</span><br><br>
# Navigate throughout the text file to confirm that ALL occurrences of uli101 have been replaced with ULI101.<br><br>
13,420
edits

Navigation menu