How to find/replace a character in every specific line
-
Hi,
assume i have 500,000 line ends with comma (,) like this:test,'number',null, test,'number',null, test,'number',null,i want to find/replace comma (,) with (;) in the end of for example every 50,000 line:
line 1: test,'number',null, line 50: test,'number',null, line 50,000: test,'number',null;is that possible to do with nodepad++ ?
thanks in advance
-
Here’s an example that will do it for every fifth line:
Open the Replace dialog by pressing Ctrl+h and then set up the following search parameters:
Find what box:
(?-s)((?:^.+\R){4}^.+),
Replace with box:\1;
Search mode radiobutton: Regular expression
Wrap around checkbox: tickedThen press the Replace All button.
The
4in the search expression is key to doing every 5th line. Adjust for your situation. -
Hello, @johnny27 and All,
Interesting problem ! And easy to solve with, both, regular expressions and the Column Editor ;-))
Here is the road map :
-
Open your file in Notepad++
-
Place th caret at the very beginning of the first line
-
Open the Column Editor (
Alt + C) -
Select
Number to Insert -
Type in
1in all zones -
Tick the
Leading zerosoption ( IMPORTANT ) -
Select the
Decformat, if necessary -
Click on the
OKbutton
=> Each line should be preceded with a
6digits number !
-
Now, open the
Replacedialog (Ctrl + H) -
SEARCH
(?-s)^.[50]0000(.+),|^\d{6} -
REPLACE
?1\1; -
Tick the
Wrap aroundoption -
Select the
Regular expressionsearch mode -
Click on the
Replace Allbutton
Voila ! Nice isn’t it ?
Notes :
-
The search regex contains two alternatives :
-
First, the
(?-s)in-line modifier ensures that any.regex symbol corresponds to a single standard character, only and not to a line-break char ! -
Then the part
^.[50]0000searches for any number of six digits, beginning current line and containing a0or a5at second position, followed with four0digits -
And the part
(.+),looks for theremainder of the lines, minus the,character, which is stored as group1, due to the parentheses
-
-
If current line number is not of the form
^.[50]0000, then it, necessarily, matches the second alternative :- The part
^\d{6}matches the6digits number, generated by the Column Editor, which begins any line
- The part
-
The replacement regex contains a conditional replacement
(?#....:....):-
If group
1exists ( every50,000lines ), we rewrites the group1, followed with a semi-colon -
If group
1is absent, as the negative part, after a:does not exist, the first6digits number of any line are simply deleted
-
Best Regards,
guy038
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login