How to merge two lines into 2 files....

Help with writing and playing macros

How to merge two lines into 2 files....

Postby wrznet » Sat Sep 11, 2004 3:19 pm

Hi,
What is the fastest way,how I can merge two lines that are in spearate files,then write to another file (merged lines).Example:

file1.txt contain :

AAAA
1111

file2.txt contain:

BBBB
2222

the point is make file3.txt with values from both files that would looks like below:

AAAA BBBB
1111 2222

At this moment,I made a macro script.Opened 3 windows,first window - file1.txt,second window file2.txt and third window for merged results...
The macro copy into clipboard first value from file1.txt,then I use next window value in macro and paste into third window that value from file1.txt.
Move to file2.txt and copy paste again to third window...So it do what I need.
however that way is terrible slow.My time wait is more then few days if I will do that !
Maybe can someone suggest a faster way to do what i have described ?
Thanks.
User avatar
wrznet
Basic User
Basic User
 
Posts: 11
Joined: Sun Aug 29, 2004 11:00 pm

Re: How to merge two lines into 2 files....

Postby Mofi » Thu Oct 28, 2004 9:48 am

Here is a macro, which should be faster because no window/document swapping is used.

Make sure, that only the two source files are open in UE.

The macro copies the whole content of the active file (source 1) to a new file, checks if last line is an empty line and set a bookmark to the end of the content of the first file (bookmark 2 on first line of file 2).

Then it copies the whole content of the second file to the new file, checks if last line is an empty line, jumps to top of the new file and sets a bookmark (bookmark 1 on the actual line of file 1).

In the loop:

jump to bookmark 2 (actual line of second file),
remove the bookmark,
cut the line content,
delete the unwanted line break,
set new bookmark 2,
jump to bookmark 1 (actual line of file 1),
go to end of line,
insert a space and the cutted line of file 2,
remove bookmark 1
go to next line
set bookmark 1

It works also on files with different numbers of lines, because it stops, if reached the end of file, independent if file 1 or file 2 have more lines than the other file.

If you want to see how it works, cut the whole loop (from Loop to EndLoop to a second macro and set loop count to 1 (Loop 1). Now run first the init macro to get the initial status of the new file. Then run the loop macro manually a few times to see how it works.

Tip: First copy the macro from the browser to a text window in UltraEdit and trim trailing spaces after copying. Then copy it to the macro edit window.

Here is the line merge macro:

InsertMode
ColumnModeOff
HexOff
UnixReOff
SelectAll
StartSelect
Copy
EndSelect
NewFile
Paste
IfColNum 1
Else
"
"
EndIf
ToggleBookmark
PreviousWindow
SelectAll
StartSelect
Copy
EndSelect
NextWindow
Paste
IfColNum 1
Else
"
"
EndIf
Top
ToggleBookmark
Loop
GotoBookMark
ToggleBookmark
IfEof
ExitLoop
EndIf
StartSelect
Key END
Cut
Key DEL
ToggleBookmark
GotoBookMark
IfEof
Paste
"
"
ExitLoop
EndIf
Key END
" "
Paste
ToggleBookmark
Key HOME
Key DOWN ARROW
ToggleBookmark
EndLoop
GotoBookMark
ToggleBookmark
Top
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4062
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros