search and replace question

Everything related to our flagship word processor.
Post Reply
thf
Posts: 64
Joined: 2006-10-13 11:26:49

search and replace question

Post by thf »

i have a problem with a huge search and replace project. maybe someone can help me. i think and hope that there is an easy way to get this done ( or maybe there is too much soccer around to study the manual).

So here is the question

i have rows of data containing informations like this

c8a1
c8a2
etc.

i want to replace them the following way

value c8a1 field c8a1
value c8a2 field c8a2
etc.

So i have to double the initial data and place some text in between. Placing the text before and after the data is not the problem, but i do not figure out how to "double" the data.

Thanks in advance

tom
User avatar
martin
Official Nisus Person
Posts: 5228
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: search and replace question

Post by martin »

Hi Tom- doing this might be easy or not, depending on your data. If all your data takes the form: letter, number, letter, number then it is quite simple. Just use PowerFind bubbles, which can be inserted via the gear buttons in the Find & Replace window. You'll want to use something like this:
Picture 1.png
Picture 1.png (18.1 KiB) Viewed 10888 times
thf
Posts: 64
Joined: 2006-10-13 11:26:49

Re: search and replace question

Post by thf »

Thank you for your help, Martin, this did what i wanted to do.
thf
Posts: 64
Joined: 2006-10-13 11:26:49

Re: search and replace question

Post by thf »

Hi Martin, now I have another search and replace question and hope you can help.

i have a large document with 8000 lines the following kind

line1 [3] [4]
line2 [2] [40]
...
line8000 [39] [245]

each row sores values in brackets wich are between 0 and 400
to handle them i have to place the first value after the last so that it reads

line1 [4] [3]
line2 [40] [2]
....
line8000 [245] [39]

Could you help me with that? I would be very grateful.
Ruchama
Posts: 213
Joined: 2006-08-19 18:35:27

Re: search and replace question

Post by Ruchama »

I think this should do it:
(capture is found in the "find what">"match" in the find window and captured is found in the replace window).
Attachments
Picture 6.png
Picture 6.png (54.36 KiB) Viewed 10734 times
User avatar
martin
Official Nisus Person
Posts: 5228
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: search and replace question

Post by martin »

Thanks Ruchama, your PowerFind expressions should indeed do the text massaging Tom requires.
thf
Posts: 64
Joined: 2006-10-13 11:26:49

Re: search and replace question

Post by thf »

Thanks Ruchama (and to you, Martin, too), I really really appreciate your help. It's the first time I get aware of the power of :roll: "powersearch". It must be the third time i fall in love with nisus. :love:
thf
Posts: 64
Joined: 2006-10-13 11:26:49

Re: search and replace question

Post by thf »

Um,
another question: is it possible to do a calculation in "find and replace", say my line says [4] and i want to add 2 to get as a replaced value [6]?
User avatar
martin
Official Nisus Person
Posts: 5228
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: search and replace question

Post by martin »

There isn't any way to do calculations in the replace expression, sorry. You could use some macro code and Find & Replace, but it will be quite a bit more complicated. To add 2 to the first bracketed number you could could use this macro:
PowerFind macro code
PowerFind macro code
Picture 1.png (13.47 KiB) Viewed 10687 times
Basically the Find command converts the numbers into variables $1, $2, and $3 which you can manipulate before inserting.

The PowerFind Pro equivalent of this macro looks like this:

Code: Select all

While Find 'line(\d+) \[(\d+)\] \[(\d+)\]', 'E$-W'
	$2 += 2
	Insert Text "line$1 [$3] [$2]"
End
thf
Posts: 64
Joined: 2006-10-13 11:26:49

Re: search and replace question

Post by thf »

Thanks Martin for your quick reply.

Because I thought I could do some calculations in combination with the "capture" command in "find and replace" I did a somewhat reductive description of my problem. Because I cannot figure out how to solve it, I am sorry to post again some of my silly questions.

In some of the files i get there are some lines which have the following form "(paragraph)" indicating real paragraphs. Btw the values are always rounded (no points or commas in there).

some text text text text text (paragraph)
Weight of topic 3949 50 4 (paragraph)
some text text text text (paragraph)
some text text text text (paragraph)
Weight of topic 5690 34 15 (paragraph)

So, there is a the number of that topic (the first number) the original weight (the second number) and a +value after adding something to the topic (the third number). To generate new reports i like to change the values in the mentioned lines to sums (eg. 54 in line 2 and 49 in line 5) and i want the sum replacing the original values.

Now what I did was creating a "find and replace"-macro which does the following it singles out the values which i want to change and writes:

some text text text text text (paragraph)
Weight of topic 3949={{50+4}} (paragraph)
some text text text text (paragraph)
some text text text text (paragraph)
Weight of topic 5690={{34+15}} (paragraph)

I hoped to single out the problem, namely to find a way to do the calculations within the "{{ }}" areas.

I would be pleased to get further help.
User avatar
martin
Official Nisus Person
Posts: 5228
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: search and replace question

Post by martin »

The "Insert Text" command doesn't handle any calculations, besides simply splicing the contents of variables between the rest of the text (although actually this is a feature of any double-quoted string). What you'll want to do: in the "While .. End" loop body use some macro code like this:

Code: Select all

	$sum = $2 + $3
	Insert Text "Topic $1=$sum"
The first line defines the variable "sum" as the sum of the 2nd and 3rd captures matched in the find expression. The "insert text" command then handles the simple variable replacement. Hopefully that makes some sense.
thf
Posts: 64
Joined: 2006-10-13 11:26:49

Re: search and replace question

Post by thf »

That's fantastic!

Thanks a lot.
Post Reply