How to select a number and replace it in with numbers that comes in sequence in succeeding appearences
-
Could you please help me with the following search-and-replace problem I am having?
I have to choose the number assigned to num_1 and increase it by 1 in the further appearences starting with 1. Also, I have to choose num_2 and increase it by 2 in further appearences. It should start from 100.
Here is the data I currently have (“before” data):
block 1 line 1 num_1=1, num_2=100 line 3 --------------------- block 2 line 1 num_1=1, num_2=100 line 3 --------------------- block 3 line 1 num_1=1, num_2=100 line 3 --------------------- block 4 line 1 num_1=1, num_2=100 line 3 --------------------- block 5 line 1 num_1=1, num_2=100 line 3 ---------------------
Here is how I would like that data to look (“after” data):
block 1 line 1 num_1=1, num_2=100 line 3 --------------------- block 2 line 1 num_1=2, num_2=102 line 3 --------------------- block 3 line 1 num_1=3, num_2=104 line 3 --------------------- block 4 line 1 num_1=4, num_2=106 line 3 --------------------- block 5 line 1 num_1=5, num_2=108 line 3 ---------------------
To accomplish this, I have tried using the following Find/Replace expressions and settings
I have tried using multiple selection and colum edit. But it is too tedious to select all the numbers that I need to change.
Could you please help me understand the ways to solve this problem?
Thank you.
-
@DILJITH-P-K said in How to select a number and replace it in with numbers that comes in sequence in succeeding appearences:
Could you please help me understand the ways to solve this problem?
Normal search and replace uses regular expressions (regex). However regex cannot count, and therefore cannot do what you want easily. There is a way for regex to solve it but it requires lots of data manipulation to do so.
There is a FAQ post here which can help. It does require adding a plugin to your Notepad++ environment (this is a one time process). Most of the hard work has already been done, but you will need to edit the code to suit your exact needs.
Terry
-
A plugin I am developing can do this. It is called Columns++.
After installing the plugin, start Notepad++, open your file and select the entire file. Then, from the Columns++ menu under the Plugins menu, select Search…. Fill in:
Find what:
num_1=\d+, num_2=\d+
Replace with:num_1=(?=match), num_2=(?=98+2*match)
and select Regular expression in the Search Mode box.
Then click the Replace All button.