Insert from separate file

Help with writing and playing macros

Insert from separate file

Postby meshy » Fri Mar 17, 2006 3:57 am

I have two files with strings on separated lines, and I want to insert the strings from one file into a regular place in the corresponding lines in the second file.

File 1, line 1: <string in File1>
File 2, line 1: stringInFile2

Desired output: <string in stringInFile2 File1>

File replace works for unique strings, but I dont understand 1) how to use variable strings and 2) how to do this between two files.

Any help?
Thanks in advance.
User avatar
meshy
Newbie
 
Posts: 2
Joined: Thu Mar 16, 2006 12:00 am

Re: Insert from separate file

Postby Mofi » Fri Mar 17, 2006 1:27 pm

I have understand you right this is definitively a job for a macro. Simply record one manually executed line merge with cursor position to next line and then run the macro until end of file.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4069
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Insert from separate file

Postby meshy » Fri Mar 17, 2006 6:17 pm

Thanks Mofi - but these are two different files, with different elements on each line. The only constant are the element terms:

File 1..........................File 2
------------------------|------------------
<element foo="1s"> | data="4v"
<element foo="2r"> | data="5g"

<element data="4v" foo="1s">
<element data="5g" foo="2r">

Hope this is a little clearer.
User avatar
meshy
Newbie
 
Posts: 2
Joined: Thu Mar 16, 2006 12:00 am

Re: Insert from separate file

Postby Mofi » Sat Mar 18, 2006 4:16 pm

The following macro will do what your example shows. Don't forget to enable the macro property Continue if a Find with Replace not found. Have only the 2 files open when running the macro and file 1 must have the focus.

InsertMode
ColumnModeOff
HexOff
Bottom
IfColNum 1
Else
"
"
EndIf
Top
NextWindow
Bottom
IfColNum 1
Else
"
"
EndIf
Top
TrimTrailingSpaces
Clipboard 9
Loop
IfEof
ExitLoop
EndIf
StartSelect
Key END
Copy
EndSelect
Key HOME
IfColNumGt 1
Key HOME
EndIf
Key DOWN ARROW
PreviousWindow
Find MatchCase "<element"
IfNotFound
ExitLoop
EndIf
Key RIGHT ARROW
Paste
" "
Key HOME
IfColNumGt 1
Key HOME
EndIf
Key DOWN ARROW
IfEof
ExitLoop
EndIf
NextWindow
EndLoop
ClearClipboard
Clipboard 0
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4069
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros