James Edward Gray II wrote:

> ...

> > Address:<tab>2933<sp>Hummingbird<tab>St.<tab>City:<tab>Groton<tab>State
> > :<tab>CT
> > Address:<sp>4321<tab>Sparrow<sp>Ave.<tab>City:<tab>Groton<tab>State:<ta
> > b>CT
> > . . .
> >
> > What I want to do is get all of the data between Address: and City: and
> > strip the <tab> and replace with spaces.  The only problem is that the
> > data between Address: and City: changes.  What I want in the end is:

...

> > Address:<tab>2933<sp>Hummingbird<sp>St.<tab>City:<tab>Groton<tab>State:
> > <tab>CT
> > Address:<tab.4321<sp>Sparrow<sp>Ave.<tab>City:<tab>Groton<tab>State:<ta
> > b>CT
> >
> > (notice that any <tab> in the address itself is now a <sp> with <tab>
> > both
> > before and after the address.)
> >
> > I know it involves using the s/// operator to both strip the tabs and
> > replace with <sp> but the problem is that it requires using an array
> > for
> > each address...and that is what is creating problems for me.
> >
> > Thanks...
>
> Hmm, let me think out loud a little.
>
> I think I see a pattern, so let's first change all of them to spaces.
> That's easy enough:
>
> s/\t/ /g;
>
> Now, if we switch all the spaces that are supposed to be tabs to tabs,
> we're done, right.  I bet we can handle that.  What about:
>
> s/ ([A-Za-z]:) /\t$1\t/g;
> # and...
> s/^([A-Za-z]:) /$1\t/;  # The first one is a special case

I don't think going on a character basis will work well here.  For one thing.
specifiers such as Lane, Ave., or St. are generally capitalized.  Also, some
street and city names are multiword, such as say Cherry Tree Lane, Des Moine,
etc

There is a much more subject-specific solution contained in the
specification.  Tabs After and before the field identifiers.  In this
context, the field identiifers are known, so the job should be very
straightforward:

s/ (City)| (State)/ \t$1/g;
s/(Address) |(City) /$1\t/g;

Never have to even touch any obscure character-based, and error-prone,
differentiations here.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to