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

Merging two files

Expand Messages
  • John Shotsky
    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
    Message 1 of 10 , Aug 25, 2011
    View Source
    • 0 Attachment
      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
    • Don
      Can you make up a quick example? There is of course an append command.
      Message 2 of 10 , Aug 25, 2011
      View Source
      • 0 Attachment
        Can you make up a quick example?

        There is of course an append command.



        On 8/25/2011 2:27 PM, 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
        >
        >
        >
        >
      • John Shotsky
        File1: 1. some text but there might be more 2. some more text. and there might be more File2: 1. 80 2. 90 Result wanted: File1: 1. some text but there might be
        Message 3 of 10 , Aug 25, 2011
        View Source
        • 0 Attachment
          File1:
          1. some text but there might be more
          2. some more text. and there might be more

          File2:
          1. 80
          2. 90

          Result wanted:
          File1:
          1. some text but there might be more 80
          2. some more text. and there might be more 90

          Appending places file2 contents at the bottom of the file1 - not what is wanted.

          This needs to run as an automated clip, with no user interaction. The files are in place, and their names are known to
          the system. Just looking for the most efficient way to do it.

          Regards,
          John


          -----Original Message-----
          From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of Don
          Sent: Thursday, August 25, 2011 13:05
          To: ntb-clips@yahoogroups.com
          Subject: Re: [Clip] Merging two files

          Can you make up a quick example?

          There is of course an append command.



          On 8/25/2011 2:27 PM, 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
          >
          >
          >
          >


          ------------------------------------

          Fookes Software: http://www.fookes.com/
          NoteTab website: http://www.notetab.com/
          NoteTab Discussion Lists: http://www.notetab.com/groups.php

          ***
          Yahoo! Groups Links
        • Art Kocsis
          John, Your original question was quite clear in what you wanted. The process is quite simple and short: Set the delimiter to ^P Input each file into separate
          Message 4 of 10 , Aug 25, 2011
          View Source
          • 0 Attachment
            John,

            Your original question was quite clear in what you wanted.

            The process is quite simple and short:
            Set the delimiter to ^P
            Input each file into separate arrays
            Append each array element (in sequence), and output to the new file.
            BTW, the meat of this was all detailed in the clips I sent you in Feb.

            ^!SetListDelimiter ^P
            ^!SetArray %File1%=^$GetFileText("^%oldFile1%")$
            ^!SetArray %File2%=^$GetFileText("^%oldFile2%")$
            ;Execute the next line for all element of the arrays i = 1, 2, ... max
            ^!AppendtoFile ^%newFile% ^%File1^%i%%^%File2^%i%%^%nl%

            Obviously, you have to define the file name variables and check for unequal
            # of array elements and other conditions.

            Namaste', Art

            At 08/25/2011 13:53, you wrote:
            >File1:
            >1. some text but there might be more
            >2. some more text. and there might be more
            >
            >File2:
            >1. 80
            >2. 90
            >
            >Result wanted:
            >File1:
            >1. some text but there might be more 80
            >2. some more text. and there might be more 90
            >
            >Appending places file2 contents at the bottom of the file1 - not what is
            >wanted.
            >
            >This needs to run as an automated clip, with no user interaction. The
            >files are in place, and their names are known to
            >the system. Just looking for the most efficient way to do it.
            >
            >Regards,
            >John
            >
            >-----Original Message-----
            >From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On
            >Behalf Of Don
            >Sent: Thursday, August 25, 2011 13:05
            >To: ntb-clips@yahoogroups.com
            >Subject: Re: [Clip] Merging two files
            >Can you make up a quick example?
            >There is of course an append command.
          • loro
            ... 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
            Message 5 of 10 , Aug 27, 2011
            View Source
            • 0 Attachment
              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
            • 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 6 of 10 , Aug 27, 2011
              View Source
              • 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 7 of 10 , Aug 27, 2011
                View Source
                • 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 8 of 10 , Aug 27, 2011
                  View Source
                  • 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 9 of 10 , Aug 27, 2011
                    View Source
                    • 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 10 of 10 , Aug 29, 2011
                      View Source
                      • 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.