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

RE: [Clip] Merging two files

Expand Messages
  • John Shotsky
    I want this to be a completely automatic process with no manual intervention. It is just one bit in a long string of clips. As in my example, I m just adding
    Message 1 of 10 , Aug 27, 2011
    • 0 Attachment
      I want this to be a completely automatic process with no manual intervention. It is just one bit in a long string of
      clips. As in my example, I'm just adding page numbers to the end of every line. As I mentioned, I have a way to do it,
      but I don't think it's very efficient � copying file2 to the bottom of file1, then moving each line, one by one, until
      file2 lines are all gone.

      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.

      Using arrays, it would just add the two arrays together in a single operation with the contents of array 2 pasted onto
      the ends of the lines in array 1. I just don't know how to code this function.

      Example:
      File 1 has 10 lines of varying lengths.
      File 2 has 10 lines of varying lengths.
      There is nothing by which to key these lines.
      The clip should place whatever is in file2 on the ends of the file1 lines.

      In yet another example, I want to insert the lines in file2 as standalone lines in file1, but in specific, controlled
      locations. Once I have the basic methodology set up, I can modify how it works to achieve each need.

      Regards,
      John

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


      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'd use the Modify Block tools. You just need to see to that the
      lines in the document you want to paste the content of the other one
      into have the same length. Fill them with blanks when needed and add
      extra spaces for margin if you want two separated columns as the
      result of the operation. If you don't want two straight columns, but
      rather want the new line to continue where the first ends, it's easy
      to remove the extraneous spaces afterwards, by Find % Replace or clip.

      Lotta



      [Non-text portions of this message have been removed]
    • Art Kocsis
      I posted the specific method and code that you want two days ago! http://tech.groups.yahoo.com/group/ntb-clips/message/22020 Art
      Message 2 of 10 , Aug 27, 2011
      • 0 Attachment
        I posted the specific method and code that you want two days ago!

        http://tech.groups.yahoo.com/group/ntb-clips/message/22020

        Art


        At 08/27/2011 09:00, you wrote:
        >I want this to be a completely automatic process with no manual
        >intervention. It is just one bit in a long string of
        >clips. As in my example, I'm just adding page numbers to the end of every
        >line. As I mentioned, I have a way to do it,
        >but I don't think it's very efficient ­ copying file2 to the bottom of
        >file1, then moving each line, one by one, until
        >file2 lines are all gone.
        >
        >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.
        >
        >Using arrays, it would just add the two arrays together in a single
        >operation with the contents of array 2 pasted onto
        >the ends of the lines in array 1. I just don't know how to code this function.
        >
        >Example:
        >File 1 has 10 lines of varying lengths.
        >File 2 has 10 lines of varying lengths.
        >There is nothing by which to key these lines.
        >The clip should place whatever is in file2 on the ends of the file1 lines.
        >
        >In yet another example, I want to insert the lines in file2 as standalone
        >lines in file1, but in specific, controlled
        >locations. Once I have the basic methodology set up, I can modify how it
        >works to achieve each need.
        >
        >Regards,
        >John
        >
        >From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On
        >Behalf Of loro
        >Sent: Saturday, August 27, 2011 07:25
        >To: ntb-clips@yahoogroups.com
        >Subject: Re: [Clip] Merging two files
        >
        >
        >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'd use the Modify Block tools. You just need to see to that the
        >lines in the document you want to paste the content of the other one
        >into have the same length. Fill them with blanks when needed and add
        >extra spaces for margin if you want two separated columns as the
        >result of the operation. If you don't want two straight columns, but
        >rather want the new line to continue where the first ends, it's easy
        >to remove the extraneous spaces afterwards, by Find % Replace or clip.
        >
        >Lotta
      • flo.gehrke
        ... John, If the two files should be combined line by line like... file1 line #1 + file2 line #1 file1 line #2 + file2 line #2 etc... I think this is
        Message 3 of 10 , Aug 27, 2011
        • 0 Attachment
          --- In ntb-clips@yahoogroups.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.

          John,

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

          file1 line #1 + file2 line #1
          file1 line #2 + file2 line #2
          etc...

          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

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

          :Out
          ; 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

          :Loop
          ^!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.

          Regards,
          Flo
        • John Shotsky
          Thank you, Flo and Art! I m on another task right now, but will get back to this in a day or two. Regards, John From: ntb-clips@yahoogroups.com
          Message 4 of 10 , Aug 27, 2011
          • 0 Attachment
            Thank you, Flo and Art! I'm on another task right now, but will get back to this in a day or two.

            Regards,
            John

            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.

            John,

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

            file1 line #1 + file2 line #1
            file1 line #2 + file2 line #2
            etc...

            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

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

            :Out
            ; 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

            :Loop
            ^!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.

            Regards,
            Flo



            [Non-text portions of this message have been removed]
          • 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 5 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.