When I need to use Windows either for Microsoft Office products or some other reason I find myself in Notepad++ a lot. Notepad++ is a great free tool that provides a ton of functionality including the ability to easily add plugins, etc. One great feature of Notepad++ is the Regular Expression capabilities when using find/replace. If you wanted to add data to the beginning of each line or add data to the end of each line you can easily do so using find and replace with Regular Expressions enabled as shown in the below examples.
Notepad++ Sample Data:
We are going to be using a really easy set of sample data to show how to append and prepend data to every line using Notepad++. We have a single text file with one, two, three, four, five, six, seven, eight, nine, and ten all on a single line as shown in the below example image.
In the examples below we are going to add the text “prepend” to the beginning of each line and the text “append” to the end of each line. We will be using Notepad++’s find and replace window with Regular Expressions enabled to accomplish our goals. In the end each line will be similar to “prepend one append”. To open Notepad++’s Find & Replace window click the Search menu in the top navigation bar and select Replace from the drop down as shown in the below example image.
Notepad++ Search Menu:
Once you click Replace the Notepad++ Replace window will display as shown in the below example image.
Notepad++ Replace Window:
We are now ready for the first example where we will prepend data to each line in the text file. Again in this example we will be adding “prepend” without quotes to the beginning of each line. We will accomplish this by using a regular expression in the Find field which is (.+) as shown in the example below.
Prepend Data To Every Line With Notepad++:
In the Replace window’s Find field add “(.+)” and then in the Replace field add “prepend \1” as shown in the example image below. If you did not want a space after prepend you would add “prepend\1” in the Replace field instead.
Now click the Replace All button and “prepend ” will be added to the beginning of each line as shown in the below example.
Text Added To The Beginning Of Each Line With Notepad++:
Now that you can see how easy that is lets do it again to add text to the end of each line.
Append Data To Every Line With Notepad++:
In the Replace window’s Find field add “(.+)” and then in the Replace field add “\1 append” as shown in the example image below. If you did not want a space before append you would add “\1append” in the Replace field instead.
Now click the Replace All button and ” append” will be added to the end of each line as shown in the below example.
Text Added To The End Of Each Line With Notepad++:
The image above shows the end result of adding text to the beginning of each line followed by adding text to the end of each line using Notepad++. Having the capabilities of regular expressions in Notepad++ is awesome!