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

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

11
Basic UserBasic User
11

    Sep 11, 2004#1

    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.

    6,675585
    Grand MasterGrand Master
    6,675585

      Oct 28, 2004#2

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

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

      The macro copies the whole contents 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 contents of the first file (bookmark 2 on first line of file 2).

      Then it copies the whole contents 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 contents,
      • 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 then cut 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 reaching the end of the file independent on file 1 or file 2 has 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.

      Hint: 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:

      Code: Select all

      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
      Best regards from an UC/UE/UES for Windows user from Austria