Re: Replace using list ...
- Don <don@...> wrote:
>You could indeed build two corresponding arrays from your tab-separated list*, one for codes, one for names:
> Needing a creative spark.
> I have two lists ... the first has lines like follows:
> D;Young;Dylan;;M;;Detroit Catholic Central;Detroit Catholic
> 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;;;;;;;;;;;;;;
> 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;;;;;
> 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.
Then in the first list swap first found instances of names with their matching codes:
^!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.
> :LoopLike your idea and Axel's.
> ^!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.
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.
- diodeom wrote:
> Then in the first listI 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?
- 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 fileTwo 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.
> you're working on?
- diodeom wrote:
> Two clips, actuallyI 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.