Loading ...
Sorry, an error occurred while loading the content.

Re: [Clip] Merging two files

Expand Messages
  • Ian NTnerd
    John, If the files are large you may want to look at join a command line tool from GnuWin32 CoreUtils. It does what you want. I d construce the command line
    Message 1 of 10 , Aug 29, 2011
    • 0 Attachment
      John,

      If the files are large you may want to look at "join" a command line
      tool from GnuWin32 CoreUtils. It does what you want. I'd construce the
      command line in NT and let join do the work.

      Art's array is good too. You could parse the File2 to split on space so
      that you don't add the unique number again.

      ; set arrays as per Art's example. Rename array names so it does not end
      in a number.
      ^!SetListDelimiter ^P
      ^!SetArray %FileA%=^$GetFileText("^%oldFile1%")$
      ^!SetArray %FileB%=^$GetFileText("^%oldFile2%")$
      ; Use the "loop element" from clip assistant
      ^!Set %Index%=0
      ^!Set %LoopCount%=^%FileA0%
      ^!IfCancel End
      :LoopStart
      ^!Inc %Index%
      ^!If ^%Index% > ^%LoopCount% EndLoop
      ; add safety line to skip empty lines usually at the end of a file.
      ^!if "^%File1^%index%%"="" LoopStart

      ; set up to parse the second file after the unique number. Assumes only
      one space in lines in file2
      ^!setlistdelimiter " "
      ^!setarray %linedata%=^%File2^%index%%
      ^!AppendtoFile "^%newFile%" ^%File1^%index%% ^%linedata2%^%nl%

      ^!GoTo LoopStart
      :EndLoop

      Ian

      On 26/08/2011 4:27 AM, John Shotsky wrote:
      > I'm looking for a standard way to add the contents of a file (file2) to the ends of the matching lines of another file.
      > (file1)
      >
      > Both files have the same number of lines, and I can begin each line with a number, such as 1., 2., if needed. Or they
      > can both start with a unique text name. There will never be duplicate lines within either file.
      >
      > I have been doing this by copying the contents of file2 to the bottom of file1, then using a replace statement to
      > replace the first line with itself plus the desired contents of the lower matching line, which is consumed in the
      > process. When no more matches are found, it is done. There is no row counting, etc, just an 'IfError Next Else Skip_-1
      > to keep repeating the process until all the lower lines are consumed.
      >
      > Is there a more direct way to do this? I'd like to create a general purpose clip that would add any file2 to any file1
      > without first copying file2 into file1, then processing them. There will always be a key at the beginning of these lines
      > in both files, but otherwise the content of each line will be different. I suspect there is a way to do this with an
      > array, but I don't know how to construct that.
      >
      > One example of this would be adding page numbers found only in file2 to each matching line in file1.
      >
      > Thanks!
      > John
      >
      >
      >
      >
      > ------------------------------------
      >
      > Fookes Software: http://www.fookes.com/
      > NoteTab website: http://www.notetab.com/
      > NoteTab Discussion Lists: http://www.notetab.com/groups.php
      >
      > ***
      > Yahoo! Groups Links
      >
      >
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.