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

22026RE: [Clip] Merging two files

Expand Messages
  • John Shotsky
    Aug 27, 2011
      Thank you, Flo and Art! I'm on another task right now, but will get back to this in a day or two.


      From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of flo.gehrke
      Sent: Saturday, August 27, 2011 13:56
      To: ntb-clips@yahoogroups.com
      Subject: Re: [Clip] Merging two files

      --- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com> , "John Shotsky" <jshotsky@...> wrote:
      > I want a general purpose method, because there are different
      > cases of what needs to be done. In some cases, each line in
      > file1 and file2 start with the same words, which facilitates
      > the match. In other cases, there will be two files with
      > simply the same number of lines, but I want the same process to
      > occur � the contents of file2 appear on the ends of each
      > File1 line, but without matching words in file2.


      If the two files should be combined 'line by line' like...

      file1 line #1 + file2 line #1
      file1 line #2 + file2 line #2

      I think this is perfectly achieved with Art's idea (message #22020) according with your sample.

      Completing Art's proposal and providing that both File1 and File2 contain the same amount of lines you could try...

      ^!SetListDelimiter ^%NL%
      ^!SetArray %Left%=^$GetFileText(^$GetDocumentPath$File1.TXT)$
      ^!SetArray %Right%=^$GetFileText(^$GetDocumentPath$File2.TXT)$
      ^!Set %i%=0

      ^!Inc %i%
      ^!If ^%i% > ^%Left0% Out
      ^!AppendtoFile ^$GetDocumentPath$NewFile.TXT ^%Left^%i%% ^%Right^%i%%^%NL%
      ^!Goto Loop

      ; In case you want to replace the original File1...
      ^!RecycleFile ^$GetDocumentPath$File1.txt
      ^!RenameFile ^$GetDocumentPath$NewFile.TXT ^$GetDocumentPath$File1.txt

      If you want to see the result in a new document before saving it to the disk you might prefer the following clip. It
      also avoids empty lines...

      ^!SetListDelimiter ^%NL%
      ^!SetArray %Left%=^$GetFileText(^$GetDocumentPath$File1.TXT)$
      ^!SetArray %Right%=^$GetFileText(^$GetDocumentPath$File2.TXT)$
      ; Strip empty records from end of array (by courtesy of Eb)
      ^!If "^%Left^%Left0%%" <> "^%Empty%" Skip Else ^!Dec %Left0%
      ^!Goto Skip_-1
      ^!Set %i%=0

      ^!Inc %i%
      ^!If ^%i% > ^%Left0% End
      ^!InsertText ^%Left^%i%% ^%Right^%i%%^%NL%
      ^!Goto Loop

      If the result is correct save it as File1.TXT replacing the original file.


      [Non-text portions of this message have been removed]
    • Show all 10 messages in this topic