Replace a text wiht specific value obtained within text

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
ktabri
Posts: 1
Joined: Fri Nov 02, 2012 2:36 pm

Replace a text wiht specific value obtained within text

Post 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
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post 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
Post Reply