search and replace a set of texts
-
Hi
I am looking to search and replace a set of text like
File 1 has the below text
3:1.428238e-001):4.577779e-002,64:9.743924e-002):7.427767e-002):2.922571e-002):3.206583e-002,((((4:7.719304e-002,5:7.767254e-002):9.925778e-002,92:1.697033e-001):2.906791e-002,(7:1.281314e-001,62:1.351362e-001):2.747034e-002):1.246730e-002,((6:9.872749e-002,7:7.750112e-002):3.270381e-002,(2:1.533366e-001,91:1.316264e-001):2.139538e-002):5.698094e-002):3.332409e-002):5.389512e-002,(2:2.990773e-001,((((((6:7.144297e-002,((5:3.452890e-002,1:7.746965e-003)
File 2 has this
1 Phalera_flavescens
2 Ochrogaster_lunifer
3 Hyphantria_cunea
4 Eudocima_salaminia
5 Eudocima_phalonia
6 Grammodes_geometrica
7 Parallelia_stuposaNow in File1 I have to replace “1:” with “Phalera_flavescens:” that is I have to replace 1 with Phalera_flavescens but not in all places but only at place i have the number followed by colon. Same way I have to replace “2:” with “Ochrogaster_lunifer:” and so on.
Thanks
-
Hello, @nagoor-meerasa-mohammed, and All,
Well, you’ve provided very few information ! Your example is just a long one-line text which contains
15zones with a number followed with a colon, listed below, in reading order :3: 64: 4: 5: 92: 7: 62: 6: 7: 2: 91: 2: 6: 5: 1:Do you speak of all these numbers ?
If so, I suppose that your
File 2text should contain, at least,92items ?Have a look, first, to this post :
https://community.notepad-plus-plus.org/topic/21965/please-read-before-posting
Best Regards,
guy038
-
@nagoor-meerasa-mohammed said in search and replace a set of texts:
:
Hi guy038, Thanks for the reply. what you assumed is correct. I have posted only few lines because the full file is very large and is of not much use.
-
Hi, @nagoor-meerasa-mohammed, and All,
OK ! So, here is the road map :
-
Copy all the
File 1.txtcontents in, let’s say, a file namedFile 3.txt -
Add a separation line of, at least, three
=signs -
Append all the
File 2.txtcontents, after the separation line -
Open the Replace dialog (
Ctrl + F)-
SEARCH
(?-s)\D\K(\d+):(?=(?s:.+^=+\R.*^\1\x20)(.+))|^===+(?s).+ -
REPLACE
?1\2 -
Tick the
Wrap aroundoption -
Select the
Regular expressionsearch mode -
Click only on the
Replace Allbutton ( Do not use theReplacebutton ! )
-
-
Close the Replace dialog (
Esc) -
Save the
File 3.txtmodifications (Ctrl + S)
Here is an example where I copied your
File 1.txttext, twice, then the separation line=====and, finally yourFile 2.txttext3:1.428238e-001):4.577779e-002,64:9.743924e-002):7.427767e-002):2.922571e-002):3.206583e-002,((((4:7.719304e-002,5:7.767254e-002):9.925778e-002,92:1.697033e-001):2.906791e-002,(7:1.281314e-001,62:1.351362e-001):2.747034e-002):1.246730e-002,((6:9.872749e-002,7:7.750112e-002):3.270381e-002,(2:1.533366e-001,91:1.316264e-001):2.139538e-002):5.698094e-002):3.332409e-002):5.389512e-002,(2:2.990773e-001,((((((6:7.144297e-002,((5:3.452890e-002,1:7.746965e-003) 3:1.428238e-001):4.577779e-002,64:9.743924e-002):7.427767e-002):2.922571e-002):3.206583e-002,((((4:7.719304e-002,5:7.767254e-002):9.925778e-002,92:1.697033e-001):2.906791e-002,(7:1.281314e-001,62:1.351362e-001):2.747034e-002):1.246730e-002,((6:9.872749e-002,7:7.750112e-002):3.270381e-002,(2:1.533366e-001,91:1.316264e-001):2.139538e-002):5.698094e-002):3.332409e-002):5.389512e-002,(2:2.990773e-001,((((((6:7.144297e-002,((5:3.452890e-002,1:7.746965e-003) ===== 1 Phalera_flavescens 2 Ochrogaster_lunifer 3 Hyphantria_cunea 4 Eudocima_salaminia 5 Eudocima_phalonia 6 Grammodes_geometrica 7 Parallelia_stuposaAFter clicking on the
Replace Allbutton, you should get this new text :Hyphantria_cunea1.428238e-001):4.577779e-002,64:9.743924e-002):7.427767e-002):2.922571e-002):3.206583e-002,((((Eudocima_salaminia7.719304e-002,Eudocima_phalonia7.767254e-002):9.925778e-002,92:1.697033e-001):2.906791e-002,(Parallelia_stuposa1.281314e-001,62:1.351362e-001):2.747034e-002):1.246730e-002,((Grammodes_geometrica9.872749e-002,Parallelia_stuposa7.750112e-002):3.270381e-002,(Ochrogaster_lunifer1.533366e-001,91:1.316264e-001):2.139538e-002):5.698094e-002):3.332409e-002):5.389512e-002,(Ochrogaster_lunifer2.990773e-001,((((((Grammodes_geometrica7.144297e-002,((Eudocima_phalonia3.452890e-002,Phalera_flavescens7.746965e-003) Hyphantria_cunea1.428238e-001):4.577779e-002,64:9.743924e-002):7.427767e-002):2.922571e-002):3.206583e-002,((((Eudocima_salaminia7.719304e-002,Eudocima_phalonia7.767254e-002):9.925778e-002,92:1.697033e-001):2.906791e-002,(Parallelia_stuposa1.281314e-001,62:1.351362e-001):2.747034e-002):1.246730e-002,((Grammodes_geometrica9.872749e-002,Parallelia_stuposa7.750112e-002):3.270381e-002,(Ochrogaster_lunifer1.533366e-001,91:1.316264e-001):2.139538e-002):5.698094e-002):3.332409e-002):5.389512e-002,(Ochrogaster_lunifer2.990773e-001,((((((Grammodes_geometrica7.144297e-002,((Eudocima_phalonia3.452890e-002,Phalera_flavescens7.746965e-003)
Notes :
-
The
File 2.txtlist of items, at the end ofFile 3.txt, has been deleted, too ! -
Of course, any number followed with a colon, which does not exist in the list, located after the separation line
=====, is not replaced at all, in the section before the=====line -
The
File 2.txtlist of items, at the end ofFile 3.txt, do not need to be sorted, too !
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