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

Replace using list ...

Expand Messages
  • Don
    Needing a creative spark. I have two lists ... the first has lines like follows: D;Young;Dylan;;M;;Detroit Catholic Central;Detroit Catholic
    Message 1 of 8 , Jun 2, 2010
    • 0 Attachment
      Needing a creative spark.

      I have two lists ... the first has lines like follows:
      D;Young;Dylan;;M;;Detroit Catholic Central;Detroit Catholic
      Central;;12;DT;161'05.00";E;;;;;
      D;James;Antonio;;M;;Romulus;Romulus;;12;DT;171'08.00";E;;;;;
      D;Gaumer;Justin;;M;;Holly;Holly;;12;DT;168'00.00";E;;;;;

      and

      R;East Kentwood;East Kentwood;A;M;;400;41.60;M;;;;;;;;;;;;;;
      R;Grand Blanc;Grand Blanc;A;M;;400;42.50;M;;;;;;;;;;;;;;
      R;Lansing Eastern;Lansing Eastern;A;M;;400;42.70;M;;;;;;;;;;;;;;
      R;Farmington;Farmington;A;M;;400;42.80;M;;;;;;;;;;;;;;


      All lines start with an R or a D -- and are on one line, they may wrap
      in email.

      I have a second list that is as follows:
      DCC Novi Detroit Catholic Central
      EaKe East Kentwood
      EaDe Eastpointe East Detroit
      AnBa Fair Haven Anchor Bay
      Farm Farmington
      Harr Farmington Hills Harrison
      NoFa Farmington Hills North Farmington


      There are tabs between the first and second column.
      The top lines have a school code twice --
      East Kentwood;East Kentwood

      I need the first of those two to be replaced by the four character code
      so its then:
      D;Young;Dylan;;M;;DCC;Detroit Catholic Central;;12;DT;161'05.00";E;;;;;

      and

      R;EaKe;East Kentwood;A;M;;400;41.60;M;;;;;;;;;;;;;;

      would be two example results.

      I am playing in my mind with arrays and all manner or things :-)

      In the end all first instances will be four character or less codes.

      At the end I may have one or two not matched, so I'll need to find any
      with a > 4 character set of text in the first position.
    • Axel Berger
      ... I would make the scond list into a file of clip commands like ^!Replace ;East Kentwood;East Kentwood; ;EaKe;East Kentwood; WASTI and then run that
      Message 2 of 8 , Jun 2, 2010
      • 0 Attachment
        Don wrote:
        > R;East Kentwood;East Kentwood;A;M;;400;41.60;M;;;;;;;;;;;;;;

        > I have a second list that is as follows:
        > EaKe East Kentwood

        > R;EaKe;East Kentwood;A;M;;400;41.60;M;;;;;;;;;;;;;;

        I would make the scond list into a file of clip commands like

        ^!Replace ";East Kentwood;East Kentwood;" >> ";EaKe;East Kentwood;"
        WASTI

        and then run that over the first.

        The first step could be (untried):

        ^!Replace "^(.+)\t(.*)$" >> "\^!Replace \";$2;$2;\" \>\> \";$1;$2;\"
        WASTI" WRASTI

        Axel
      • Axel Berger
        ... I overlooked that first. Make that: ^!Find ;([^;]*); 1; WRSTI Axel
        Message 3 of 8 , Jun 2, 2010
        • 0 Attachment
          Don wrote:
          > At the end I may have one or two not matched, so I'll need to
          > find any with a > 4 character set of text in the first position.

          I overlooked that first. Make that:

          ^!Find ";([^;]*);\1;" WRSTI

          Axel
        • diodeom
          ... You could indeed build two corresponding arrays from your tab-separated list*, one for codes, one for names: ^!SetArray
          Message 4 of 8 , Jun 2, 2010
          • 0 Attachment
            Don <don@...> wrote:
            >
            > Needing a creative spark.
            >
            > I have two lists ... the first has lines like follows:
            > D;Young;Dylan;;M;;Detroit Catholic Central;Detroit Catholic
            > Central;;12;DT;161'05.00";E;;;;;
            > D;James;Antonio;;M;;Romulus;Romulus;;12;DT;171'08.00";E;;;;;
            > D;Gaumer;Justin;;M;;Holly;Holly;;12;DT;168'00.00";E;;;;;
            >
            > and
            >
            > R;East Kentwood;East Kentwood;A;M;;400;41.60;M;;;;;;;;;;;;;;
            > R;Grand Blanc;Grand Blanc;A;M;;400;42.50;M;;;;;;;;;;;;;;
            > R;Lansing Eastern;Lansing Eastern;A;M;;400;42.70;M;;;;;;;;;;;;;;
            > R;Farmington;Farmington;A;M;;400;42.80;M;;;;;;;;;;;;;;
            >
            >
            > All lines start with an R or a D -- and are on one line, they may wrap
            > in email.
            >
            > I have a second list that is as follows:
            > DCC Novi Detroit Catholic Central
            > EaKe East Kentwood
            > EaDe Eastpointe East Detroit
            > AnBa Fair Haven Anchor Bay
            > Farm Farmington
            > Harr Farmington Hills Harrison
            > NoFa Farmington Hills North Farmington
            >
            >
            > There are tabs between the first and second column.
            > The top lines have a school code twice --
            > East Kentwood;East Kentwood
            >
            > I need the first of those two to be replaced by the four character code
            > so its then:
            > D;Young;Dylan;;M;;DCC;Detroit Catholic Central;;12;DT;161'05.00";E;;;;;
            >
            > and
            >
            > R;EaKe;East Kentwood;A;M;;400;41.60;M;;;;;;;;;;;;;;
            >
            > would be two example results.
            >
            > I am playing in my mind with arrays and all manner or things :-)
            >
            > In the end all first instances will be four character or less codes.
            >
            > At the end I may have one or two not matched, so I'll need to find any
            > with a > 4 character set of text in the first position.
            >

            You could indeed build two corresponding arrays from your tab-separated list*, one for codes, one for names:

            ^!SetArray %Code%=^$GetDocMatchAll(^[^\t\r]++)$
            ^!SetArray %Name%=^$GetDocMatchAll(\t\K.++)$

            Then in the first list swap first found instances of names with their matching codes:

            :Loop
            ^!Inc %N%
            ^!Replace ";(^%Name^%N%%);\1;" >> "^%Code^%N%%" WRS1
            ^!If ^%N%=^%Code0% End Else Loop

            */ Is the inconsistency in codes or names? Is there a tab after "DCC" or after "DCC Novi?" One way or another, I'd think it would help to prep them beforehand.
          • Don
            ... Like your idea and Axel s. The inconsistency is that the name in the first file might be different than the name in the second (Blank School & Preparatory
            Message 5 of 8 , Jun 2, 2010
            • 0 Attachment
              > :Loop
              > ^!Inc %N%
              > ^!Replace ";(^%Name^%N%%);\1;">> "^%Code^%N%%" WRS1
              > ^!If ^%N%=^%Code0% End Else Loop
              >
              > */ Is the inconsistency in codes or names? Is there a tab after "DCC" or after "DCC Novi?" One way or another, I'd think it would help to prep them beforehand.


              Like your idea and Axel's.

              The inconsistency is that the name in the first file might be different
              than the name in the second (Blank School & Preparatory Academy vs Blank
              School AND Preparatory Academy -- or -- Rutherford-Central vs Rutherford
              Central). After running through the first time if there are instances
              where the "code" spot is over four characters then I can adjust that
              particular school name -- there are only a couple like that.
            • Axel Berger
              ... I take it you re thinking of one clip working on both - presumably open - files. Could you elaborate a little on how to choose and swap the file you re
              Message 6 of 8 , Jun 2, 2010
              • 0 Attachment
                diodeom wrote:
                > Then in the first list

                I take it you're thinking of one clip working on both - presumably open
                - files. Could you elaborate a little on how to choose and swap the file
                you're working on?

                Thanks
                Axel
              • diodeom
                I take it you re thinking of one clip working on both - presumably open ... Two clips, actually (much like in your concept). After populating both arrays from
                Message 7 of 8 , Jun 2, 2010
                • 0 Attachment
                  I take it you're thinking of one clip working on both - presumably open
                  > - files. Could you elaborate a little on how to choose and swap the file
                  > you're working on?
                  >

                  Two clips, actually (much like in your concept). After populating both arrays from the tab-delimited doc (by the initial clip, maybe ran only once), the proper (looping) clip does its routine on the target list(s? -- maybe repetitively). I don't think there is much to be gained here by employing ^!Get/SetDocIndex (or whichever doc management functions/commands). It takes "a willing act of Don" :) to choose the docs, to clear (otherwise temporarily persisting) possibly hefty variables %Code% and %Name%, or to maybe preserve these arrays for any future use (by writing them to the second clip, or by populating a handy ini file with streamlined, paired school name/school code values), or to... -- and so on. Lots of maybes.
                • Axel Berger
                  ... I see. I tend always to forget, that arrays and other variables can persist across clips. Out of a bit of misplaced purism I prefer not to make use of
                  Message 8 of 8 , Jun 2, 2010
                  • 0 Attachment
                    diodeom wrote:
                    > Two clips, actually

                    I see. I tend always to forget, that arrays and other variables can
                    persist across clips. Out of a bit of misplaced purism I prefer not to
                    make use of that.

                    Danke
                    Axel
                  Your message has been successfully submitted and would be delivered to recipients shortly.