PDA

View Full Version : Solved: Find and replace from another documents



Pasquale
11-05-2005, 06:55 AM
Hallo I need still help.
I have a very long text in a doc. I want replace all rows that i find with this expression in find and replace: \GRK Mt [0-9]{1;3}:[0-9]{1;3}*^13 (+jolly) with the same expression also find with: \GRK Mt [0-9]{1;3}:[0-9]{1;3}*^13 (+jolly) from another doc.

I use this find expression that works in each documents.
\GRK Mt [0-9]{1;3}:[0-9]{1;3}*^13 (+jolly)

How can I replace the text of first document (books.doc) - \GRK Mt [0-9]{1;3}:[0-9]{1;3}*^13 (+jolly) - with the same expression inserted in the second documents (replace.doc) - \GRK Mt [0-9]{1;3}:[0-9]{1;3}*^13 (+jolly) -?

GRKwritten in superscripted determine the difference from other rows in first document, in the second document all rows begins with GRK superscripted.
GRK rows are in exact sequence in each documents.

Thanks pasquale

example of first document
GRK Mt 1:1 B?bloj gen?sewj 'Ihso? Cristo? u?o? Dau?d u?o? 'Abra?m.
GRT Mt 1:1 Biblos genese?s I?sou Christou huiou Dauid huiou Abraam.
CEI Mt 1:1 Genealogia di Ges? Cristo figlio di Davide, figlio di Abramo.
NVT Mt 1:1 Genealogia di Ges? Cristo, figlio di Davide, figlio di Abramo.

GRK Mt 1:2 'Abra?m ?g?nnhsen t?n 'Isa?k, 'Isa?k d? ?g?nnhsen t?n 'Iak?b, 'Iak?b d? ?g?nnhsen t?n 'Io?dan ka? to?j ?delfo?j a?to?,
GRT Mt 1:2 Abraam egenn?sen ton Isaak, Isaak de egenn?sen ton Iak?b, Iak?b de egenn?sen ton Ioudan kai tous adelphous autou,
CEI Mt 1:2 Abramo gener? Isacco, Isacco gener? Giacobbe, Giacobbe gener? Giuda e i suoi fratelli,
NVT Mt 1:2 Abramo gener? Isacco; Isacco gener? Giacobbe; Giacobbe gener? Giuda e i suoi fratelli;

example of second document
GRK Mt 1:1 B?bloj gen?sewj 'Ihso? Cristo? u?o? Dau?d u?o? 'Abra?m.
GRK Mt 1:2 'Abra?m ?g?nnhsen t?n 'Isa?k, 'Isa?k d? ?g?nnhsen t?n 'Iak?b, 'Iak?b d? ?g?nnhsen t?n 'Io?dan ka? to?j ?delfo?j a?to?,
GRK Mt 1:3 'Io?daj d? ?g?nnhsen t?n F?rej ka? t?n Z?ra ?k t?j Qam?r, F?rej d? ?g?nnhsen t?n `Esr?m, `Esr?m d? ?g?nnhsen t?n 'Ar?m,
GRK Mt 1:4 'Ar?m d? ?g?nnhsen t?n 'Aminad?b, 'Aminad?b d? ?g?nnhsen t?n Naass?n, Naass?n d? ?g?nnhsen t?n Salm?n,
GRK Mt 1:5 Salm?n d? ?g?nnhsen t?n B?ej ?k t?j `Rac?b, B?ej d? ?g?nnhsen t?n 'Iwb?d ?k t?j `Ro?q, 'Iwb?d d? ?g?nnhsen t?n 'Iessa?,



exscuse me for bad english:hi: :hi: :friends:

brettdj
11-05-2005, 05:20 PM
Hi Pasquale

Two queries

Pattern
Your replace need
I can see that this pattern (note I added spaces and replaced ";" with ",")
GRK\s{1}Mt\s{1}[0-9]{1,3}:[0-9]{1,3}
would match
GRK Mt 1:1 Bbloj gensewj 'Ihso Cristo uo Daud uo 'Abram.

what is the second portion in the pattern
*^13 (+jolly) -?
meant to match?

Can you please give a full example of what you want to match and replace. Are you looking to replace each line that matches in Doc 1, with the corresponding match in Doc 2?

GRK Mt 1:1 B?bloj gen?sewj 'Ihso? Cristo? u?o? Dau?d u?o? 'Abra?m.
with
GRK Mt 1:1 B?bloj gen?sewj 'Ihso? Cristo? u?o? Dau?d u?o? 'Abra?m.

GRK Mt 1:2 'Abra?m ?g?nnhsen t?n 'Isa?k, 'Isa?k d? ?g?nnhsen t?n 'Iak?b, 'Iak?b d? ?g?nnhsen t?n 'Io?dan ka? to?j ?delfo?j a?to?,
with
GRK Mt 1:2 'Abra?m ?g?nnhsen t?n 'Isa?k, 'Isa?k d? ?g?nnhsen t?n 'Iak?b, 'Iak?b d? ?g?nnhsen t?n 'Io?dan ka? to?j ?delfo?j a?to?,
etc

Cheers

Dave

Pasquale
11-05-2005, 10:41 PM
Hi brettdj,
thanks.
1) the pattern is

\GRK Mt [0-9]{1,3}:[0-9]{1,3}*^13 (wildcards) (in italian Office VBA "," = ";")

would match the whole row
GRK Mt 1:1 Bbloj gensewj 'Ihso Cristo uo Daud uo 'Abram.

after match
GRK Mt 1:2 'Abra?m ?g?nnhsen t?n 'Isa?k, 'Isa?k d? ?g?nnhsen t?n 'Iak?b, 'Iak?b d? ?g?nnhsen t?n 'Io?dan ka? to?j ?delfo?j a?to?

and so on always the whole row that begin with GRK.

The problem is: the text of first document (here is at the begin of the row GRK, GRT, CEI, NVT, NM.....) where GRK whole text is bad. And I must substitute the text of whole row beginning with GRK with the correct text by the second documents where rows begins with GRK (all text in second document Has GRK at the begin of row).

Are you looking to replace each line that matches in Doc 1, with the corresponding match in Doc 2? Yes.

The final result is a document the same of first document with the correct text of GRK rows.

example enclosed (only the 1 e 2 document):hi: :hi:

brettdj
11-06-2005, 03:13 AM
I realise now that you are using Word's RegExp like matching capacity and not direct RegExp.

But I don't understand what you are replacing. Are you simply trying to remove any row in doc 1 not starting with GRK?

Cheers

Dave

Pasquale
11-06-2005, 04:20 AM
Hi brettdj,
do you not understand my bad english.
This is the problem:
I have two documents.
The first have rows beginning by:
GRK the abbreviation of Greek New Trestament;
GRT the abbreviation og Greek New Testament translitterated;
CEI the abbreviation of Conference Episcopale Italiana and so on.
NVT.....
NR.....
ND.....
DIO.....
RIV....
NM.....
TILC....

Mt is the abbreviation of Matthew
1:1, 1:2----n:n, are the verses of the bible

There are ten (10) different bible interlinear readings.

The second have only one bible GRK Greek New Testament.

In the first document the text of the bible called GRK is bad (no good with error).

I must substitute the text in the first document that begin with GRK with the text of the second document that begin with GRK in sequence.

Find GRK Mt 1:1................................... of the first document

replace with GRK Mt 1:1.................of the second document

after Find GRK Mt 1:2..............of the first document
replace with GRK Mt 1:2.................of the second document

and so on.

The other bible text remain where are.

Pasquale
:dunno :dunno

brettdj
11-06-2005, 05:02 AM
Thats what I thought you wanted but I get confused with your example documents. I'll pull together a RegExp VBA solution, might take a little while for me to play with the Word Object though :)

Cheers

Dave

Pasquale
11-06-2005, 05:38 AM
Hi brettdj,
you are very kind to reply, and i thank you very very much.

Help me with VBA

Ciao Pasquale:bow:

brettdj
11-06-2005, 06:56 AM
How about this - it does presume the numbering is the same (1.1 then 1.2 etc) in each doc

Cheers

Dave


Option Explicit
Sub Greeks()
Dim Doc1 As Document, Doc2 As Document
Dim RegEx As Object
Dim RegO1 As Object, RegO2 As Object, i As Long
Set Doc1 = Documents("FirstDocument")
Set Doc2 = Documents("SecondDocument")

Set RegEx = CreateObject("vbscript.regexp")
RegEx.Global = True
RegEx.Pattern = "(GRK\s{1}Mt\s{1})([0-9]{1,3}:[0-9]{1,3})(.*?\r)"
Set RegO1 = RegEx.Execute(Doc1.Content.Text)
Set RegO2 = RegEx.Execute(Doc2.Content.Text)
'This code would need modding if the ordering system was different between docs
Application.ScreenUpdating = False
For i = 1 To RegO1.Count
If RegO1(i - 1).submatches(1) = RegO2(i - 1).submatches(1) Then
With Doc1.Content.Find
.Text = RegO1(i - 1)
.Replacement.Text = RegO2(i - 1)
.Execute Replace:=wdReplaceOne
End With
End If
Next
Application.ScreenUpdating = True
End Sub

Pasquale
11-06-2005, 07:26 AM
Hi brettdj,
I am testing the macro.

It works very very well.

It is a greater macro Thanks.

Please could you see my other trhead for merge two docs in a table?.

Thanks Pasquale