Page 1 of 1

Replace a text wiht specific value obtained within text

Posted: Fri Nov 02, 2012 3:07 pm
by ktabri
Hi Forum
I have a replacing problem. Say, that I have a text file, that occasionally contains sections similar to this below:
/COM, REAL 1
Mat, 1
R, 2

I would like to replace the number 2 in the last line (R, 2), with the number 1 obtained in from the first line after the text REAL 1, i.e. after the replacing it should appear as:

/COM, REAL 1
Mat, 1
R, 1

Is that kind of replacing be possible in TextPad?

Any help on the topic would be very much appreciated.
Kristjan

Posted: Fri Nov 02, 2012 4:24 pm
by ben_josephs
The HOW-TOs forum is not the the right one in which to ask questions. As it says in one place:
Instructional HowTos, posted by users. No questions here please
and in another:
PLEASE DO NOT POST QUESTIONS HERE

But, assuming the R line is always 2 lines down from the /COM line, here is an answer:

Use "Posix" regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
Search | Find... (<F5>):
Find what: ^(/COM, REAL )([0-9]+)\n(.*)\n(R, )[0-9]+
Replace with: \1\2\n\3\n\4\2

[X] Regular expression

Replace All