As you grow and mature your computing skills and prowess under the Linux ecosystem, you soon find yourself comfortable with the productivity status associated with the Linux command-line environment.
The fact is true, especially for users seeking to master Linux administration footprints. The nano editor is an important file editing tool for such users. It even makes more sense to use nano editor server environments where GUI is not available.
Nano text editor is not as advanced as the likes of vim editor but it qualifies as the perfect starting point before Linux users can transition to those other text editors.
This article will walk us through searching and replacing text on a file opened under the nano text editor in Linux systems.
Why Search and Replace Text?
The search and replace text functionality in nano editor is a key solution to many practical problems. For instance, consider the scenario where you are dealing with a very large document file. Maybe this document is a documentation file of an old software version release.
Given the fact that a new software version release is out, we might only need to replace some keywords on the old software documentation file for it to match the properties of the new software version release. Such an instance calls for a search and replace text expertise.
For this guide to make more sense, we need a sample file with some text to successfully demonstrate the search and replace text functionality in the nano editor.
Consider the following file opened by the nano editor.
We are going to assume that we are dealing with an extremely large file that is not easily scrollable.
Search and Replace Text in Nano Editor
In reference to the above screen capture, let us assume we want to search for the text “Linux” and replace it with the text “LinuxShellTips”.
To launch the search bar, use the keyboard key combination
We can now key in the text we want to search and replace throughout the file:
[Enter] on your keyboard.
You will now be required to key in the replacement text for your previously searched text.
Once you hit enter on your keyboard, you will have the option of confirming the replacement of each text match found or agreeing to replace all the text that matched the search at once.
Once done, you will have successfully replaced the searched text.
You can now comfortably search and replace text in a nano text editor. Hope the article guide was helpful. Feel free to leave a comment or feedback.