[NTLUG:Discuss] YA script question.
Victor Brilon
victor at vail.net
Tue Aug 13 20:03:59 CDT 2002
So this little script will get you 90% there. Give it your data file as
an argument:
#!/usr/bin/perl -w
$/=""; # To get rid of blank lines
while (<>) {
s/[\r\n]+/,/g; # Get rid of line break and add a comma
# Get rid of the spaces around comma in zip code
# And make zip code first
s/(.+) , (\d+)/$2,$1/;
# Get rid of the comma at the end
s/,$//g;
print;
print "\n";
}
Using your example data set this produces:
12345,123 street1,city1 st
54321,321 street2, suite A,city1 st
The problem with this is twofold:
1) You don't specify how embedded commas are represented so I don't know
how to get rid of them
2) Your fields aren't consistent. How do you handle blank fields? I.E.,
in the first example the street is the last field on line 1. In the
second example, it's the Suite number. How is the program to
automagically detect that? Are there blank filed holders indicated via
commas?
Victor
Bobby Wrenn wrote:
> A little background on what I am trying to accomplish.
>
> I get address lists from our sales people. Of course they come in all
> shapes and sizes. Mostly M$ spreadsheets.
>
> Since the data comes from the customer it is seldom in a format I can
> run through my zone software. I would like to preserve as much of the
> original data as possible. With the help of this list I have cut my turn
> around time by over 50%.
>
> Here is the latest wrinkle. I have a spreadsheet that looks like this:
>
> 123 street1
> city1 st , 12345
>
> 321 street2, suite A
> city1 st , 54321
>
> Each record is two lines with a blank line seperating records. I need
> the two lines for each record combined into a single line and comma
> seperated. I also need to remove any embedded commas and remove the
> space before and after the comma in front of the zip code. Then just to
> make it enteresting and because my locator program requires it. I need
> to make the zip code the first field.
>
> TIA
> Bobby
>
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
More information about the Discuss
mailing list