497

I'm using Notepad++ and I can't figure this out :

I have numerous lines all starting with http. I need to add some text in front of it in every line. Also, I need to add different text to the end of each line. Each line ends differently.

What is the fastest way to add text to the start and end of each line?

6
  • 2
    Replace with regular expressions. Replace end of line (I do not recall which symbol it is) with [myText]end of line
    – SJuan76
    Jun 12, 2012 at 19:51
  • look notepad-plus-plus.org for how to use this tool
    – bjan
    Jun 12, 2012 at 19:52
  • Do you want add the same text to each line?
    – Max
    Jun 12, 2012 at 19:54
  • use same text at start of each line
    – johnkol
    Jun 12, 2012 at 20:14
  • 1
    same text at end of each line. end text is different than start text though. also I did look on how to use the tool and im lost, this why im asking. thank you for any help
    – johnkol
    Jun 12, 2012 at 20:15

13 Answers 13

1067

Follow these steps:

  1. Press Ctrl+H to bring up the Find/Replace Dialog.
  2. Choose the Regular expression option near the bottom of the dialog.

To add a word, such as test, at the beginning of each line:

  1. Type ^ in the Find what textbox
  2. Type test in the Replace with textbox
  3. Place cursor in the first line of the file to ensure all lines are affected
  4. Click Replace All button

To add a word, such as test, at the end of each line:

  1. Type $ in the Find what textbox
  2. Type test in the Replace with textbox
  3. Place cursor in the first line of the file to ensure all lines are affected
  4. Click Replace All button
4
  • 9
    You can replace only 6561963 lines.
    – duslabo
    Mar 18, 2013 at 13:00
  • 14
    While creating SQL-queries, I had to use \ as an escape character: '\);
    – Wietse
    Aug 18, 2014 at 9:21
  • Very cool, thank you so very much for this one. Apr 26, 2022 at 17:52
  • To those who need to add a special character, you need to use \ as an escape character. Special characters: ., +, *, ?, ^, $, (, ), [, ], {, }, |, \.
    – Amos
    May 11, 2022 at 5:47
161
  1. Move your cursor to the start of the first line
  2. Hold down Alt + Shift and use the cursor down key to extend the selection to the end of the block

This allows you to type on every line simultaneously.

I found the solution above here.

I think this is much easier than using regex.

4
  • 11
    This will only work for the beginning of a line, if the lines are all different lengths
    – Dman
    Jun 15, 2016 at 15:09
  • 4
    I was very pleased to discover that I could drag my mouse instead of using the down key and it still worked. Even better, I can just scroll down to the final line I'm going to select and ctrl+alt+shift then click worked exactly like I hoped it would.
    – Denial
    Jun 30, 2016 at 17:16
  • 1
    TBH this is really the only thing that keeps pushing me to move to Sublime editor...so many years of requests too, it's a shame. Nov 9, 2020 at 23:29
  • Is there a way to do this at the end of lines of variable length, though?
    – endolith
    Jan 1 at 19:15
32

Notepad++ has a very powerful editing capability. (Today I'm searching for the similar function in Sublime Text), but for Notepad++, just hold Alt when you drag the mouse. What you type will then replace the selected column on every line. To insert without replacing existing text, use Alt-Shift.

enter image description here

3
  • 3
    This should be voted much higher. Because contrary to what one may think when reading "editing the whole column", this allows adding text to the beginning of all lines without replacing anything.
    – bers
    Jul 2, 2015 at 19:08
  • I think you did a mistake there ;) @JimR Alt + Shift will overwrite the text and Alt inserts (at least for me) Nov 16, 2016 at 10:46
  • 1
    control right mouse will column select in sublime text as you describe.
    – Hogan
    Feb 10, 2017 at 23:29
31

Notepad++ Add Word To Start Of Every Line

Follow this instruction to write anything at the start of every line with Notepad++

Open Notepad++,

Press Cntrl+H open the Find/Replace Dialog.

Now type ^ in the Find what textbox (Type ^ without any spaces)

Type anything(like in our example I am writing "John ") in the Replace with textbox (Write text one/more space for adding one/more space after your text in every line)

Select the Regular Expression option

Place your cursor in the first line of your file to ensure all lines are affected

Click Replace All button

enter image description here

enter image description here

Notepad++ Add Text To End Of Every Line

Follow this instruction to write anything at the end of every line with Notepad++

Open Notepad++,

Press Cntrl+H open the Find/Replace Dialog.

Now type $ in the Find what textbox (Type $ without any spaces)

Type anything(like in our example I am writing " John") in the Replace with textbox (Write one/more space text for adding one/more space before your text in every line)

Select the Regular Expression option

Place your cursor in the first line of your file to ensure all lines are affected

Click Replace All button

enter image description here

enter image description here

For all Notepadd++ Tutorials: VISIT:)

1
  • This appears very similar to many other answers here. Can you edit it to explain what new insights your answer gives to the topic. Answers that just repeat existing information are not helpful. Answering is good but I recommend you look for questions with no accepted answers or with only a few poor (or incomplete) answers. Note that "Notepad++" only has one "d".
    – AdrianHHH
    Jul 20, 2020 at 7:15
26

Here is my answer. To add ');' to the end of each line I do 'Find What: $' and 'Replace with: \);' you need to do escape; enter image description here

0
21

You can automatically do it in Notepad++ (add text at the beginning and/or end of each line) by using one regular expression in Replace (Ctrl+H):

enter image description here

Explanation: Expression $1 in Replace with input denotes all the characters that include the round brackets (.*) in Find what regular expressin.

Tested, it works.

Hope that helps.

19

Well, I am posting this after such a long time but this will the easiest of all.

  1. To add text at the beginning/a-certain-place-from-start for all lines, just click there and do ALT+C and you will get the below box. Type in your text and click OK and it's done.

    enter image description here

  2. To add a certain text at end of all lines, do CTRL+F, and choose REPLACE. You will get the below box. Put in '$' in 'find what' and in 'replace with' type in your text.Make sure you choose 'regular expression' in the search mode (left down). Finally click 'replace all' and you are done.

enter image description here

15

Open Notepad++, then click Ctrl+ F.

Choose Regular Expression

*Find What: "^" (which represents index of the each line - "PREFIX").

Replace with : "anyText"*

enter image description here

For Suffix on each line: Follow the same steps as above "Replace ^ with $" . That's it.

4

To append different text to the end of each line, you can use the plugin ConyEdit to do this.
With ConyEdit running in the background, follow these steps.

  1. use the command line cc.gl a to get lines and store in an array named a.
  2. use the command line cc.aal //$a to append after each line, using the contents of array a.

Example
enter image description here

3

If you have thousands of lines, I guess the easiest way is like this:

-select the line that is the start point for your cursor

-while you are holding alt + shift select the line that is endpoint for your cursor

That's it. Now you have a giant cursor. You can write anything to all of these lines.

3

In order to do it in one go:

  1. Copy and paste the following example text in your notepad++ window:

http:\blahblah.com

http:\blahnotblah.com

http:\blahandgainblah.com

  1. Press Ctrl+H on the notepad++ window
  2. In the Find what box type: ^(.+)$. Here ^ represents the start of the line. $ represents the end of the line. (.+) means any character in between the start and the end of the line and it would be group 1.
  3. In the Replace with box type: WhateverFrontText(\1)WhatEverEndText. Here (\1) means whatever text in a line.
  4. Check the check box Wrap around
  5. Search mode: Regular expression
  6. Result:

WhateverFrontTexthttp:\blahblah.comWhatEverEndText

WhateverFrontTexthttp:\blahnotblah.comWhatEverEndText

WhateverFrontTexthttp:\blahandgainblah.comWhatEverEndText

  1. Screenshot of the notepad++ options and result: enter image description here
1
  • 3
    Why are you putting \1 inside parenthesis in "replace with"? Also it's better to use $1, \1 is a very old practice.
    – Toto
    Apr 26, 2019 at 13:43
2

Simply in the "Find what:" field, type \r. This means "Ends of the Row". In the "Replace with:" field, you put what you want for instance .xml

if you have several lines, and you are aiming to add that text to the end of the each line, you need to markup the option ". matches newline" in the "Search Mode" group box.

Example:

You have a file name list, but you want to add an extension like .xml. This would be what you need to do and Bang! One shot!:

See the image here

1

Please find the Screenshot below which Add a new word at the start and end of the line at a single shot

adding a new word at the start & end of the every line in Notepad++ at a single shot

Not the answer you're looking for? Browse other questions tagged or ask your own question.