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

clip to open two files and then replace specific lines

Expand Messages
  • Don
    I have two files. I will call one the update file as it has new data and the other the base file as it is the base I am trying to keep current. Each line in
    Message 1 of 3 , Oct 18, 2012
    • 0 Attachment
      I have two files. I will call one the update file as it has new data
      and the other the base file as it is the base I am trying to keep current.

      Each line in the update file will have lines that start with a number
      followed by a comma and then data. They are never more than one line.

      ####,rest of line

      #### is a number it may be one digit like 1 or 10 digits like 1000098000.

      The number is always followed by a comma and there is no other comma on
      a line.

      Here is some actual data that would be in the base file:
      Num,Tag
      1,058001e0f083
      2,058001e578f2
      3,058001e56e9d
      4,058001ea29c1
      5,058001e4e6fa
      6,058001e9b195
      7,058001e512e9
      8,058001e56f7d

      I want to go line by line in my update file (of course I don't literally
      have to go line by line is there is some fancy array method or doc match
      all or whatever) and then replace the same line in the base file.

      So if I had an update file it might look like this:
      Num,Tag
      2,05800159804d
      7,0580015dc5de
      8,0580023f9e29

      So those three lines would replace the prior line in the base file.

      So tasks I need to do...
      1. find the two files and tell my clip to work on these two files
      2. find the lines that need to be replaced and replace them
      3. save the base file with a sequential number so that I can always go
      to the most recent file but don't lose the prior file.

      I am stumped already on the first part ... how to select my two files.


      b
    • Ian NTnerd
      Don, I think the code I gave your Time Stats question covers most of what you need. You just need to modify it so for each line of the modification file you
      Message 2 of 3 , Oct 19, 2012
      • 0 Attachment
        Don,

        I think the code I gave your Time Stats question covers most of what you
        need.

        You just need to modify it so for each line of the modification file you
        find the right line in the Master file and update that with the new number.

        Ian

        On 19/10/2012 10:27 AM, Don wrote:
        >
        > I have two files. I will call one the update file as it has new data
        > and the other the base file as it is the base I am trying to keep current.
        >
        > Each line in the update file will have lines that start with a number
        > followed by a comma and then data. They are never more than one line.
        >
        > ####,rest of line
        >
        > #### is a number it may be one digit like 1 or 10 digits like 1000098000.
        >
        > The number is always followed by a comma and there is no other comma on
        > a line.
        >
        > Here is some actual data that would be in the base file:
        > Num,Tag
        > 1,058001e0f083
        > 2,058001e578f2
        > 3,058001e56e9d
        > 4,058001ea29c1
        > 5,058001e4e6fa
        > 6,058001e9b195
        > 7,058001e512e9
        > 8,058001e56f7d
        >
        > I want to go line by line in my update file (of course I don't literally
        > have to go line by line is there is some fancy array method or doc match
        > all or whatever) and then replace the same line in the base file.
        >
        > So if I had an update file it might look like this:
        > Num,Tag
        > 2,05800159804d
        > 7,0580015dc5de
        > 8,0580023f9e29
        >
        > So those three lines would replace the prior line in the base file.
        >
        > So tasks I need to do...
        > 1. find the two files and tell my clip to work on these two files
        > 2. find the lines that need to be replaced and replace them
        > 3. save the base file with a sequential number so that I can always go
        > to the most recent file but don't lose the prior file.
        >
        > I am stumped already on the first part ... how to select my two files.
        >
        > b
        >
        >



        [Non-text portions of this message have been removed]
      • flo.gehrke
        ... Hi Don, I would propose to name the base files as base-001.txt. base-002.txt etc up to base-999.txt. So you could automatically find the latest version
        Message 3 of 3 , Oct 27, 2012
        • 0 Attachment
          --- In ntb-clips@yahoogroups.com, Don <don@...> wrote:
          >
          > I have two files. I will call one the update file as it has new
          > data and the other the base file as it is the base I am trying to
          > keep current.
          > (...)
          > So tasks I need to do...
          > 1. find the two files and tell my clip to work on these two files
          > 2. find the lines that need to be replaced and replace them
          > 3. save the base file with a sequential number so that I can always go
          > to the most recent file but don't lose the prior file.
          >
          > I am stumped already on the first part ... how to select my
          > two files.

          Hi Don,

          I would propose to name the base files as base-001.txt. base-002.txt etc up to base-999.txt. So you could automatically find the latest version with the following clip and save the updated version with an increased number. Tested with Ntb Pro 7.1:


          ^!Set %Files%=^$GetFileFirst(^$GetDocumentPath$;"base*.txt";;Name)$

          :Loop
          ^!Set %Last%=^$GetFileName(^%Files%)$
          ^!Set %Files%=^$GetFileNext$
          ^!IfEmpty ^%Files% Open
          ^!Goto Loop

          :Open
          ^!CloseFileFind
          ^!Open ^%Last%
          ; Insert updating here
          ^!Info [L]Updating lines should follow here.^PClick OK to save this^Pfile with an increased number

          :Save
          ^!Set %Nr%=^$StrCopyRight("^$GetFileName(^#)$";3)$
          ^!Inc %Nr%
          ^!Set %Nr%=^$StrCopyRight("00^%Nr%";3)$
          ^!Save as base-^%Nr%.txt


          Do you still have any problem with updating the base files? If so, drop us a line, and we'll look after that...

          Regards,
          Flo
        Your message has been successfully submitted and would be delivered to recipients shortly.