Solved

perl or Simple Excel macro

Posted on 2014-01-28
4
329 Views
Last Modified: 2014-01-28
Hi ,

I have data like below.

Detmolder Str. 515 33605 Bielefeld

Should be like this when seperated:

Detmolder Str. 515 , 33605 Bielefeld

So the format schould be:

ADDRESS ,ZIP CITY

So that it takes the address line in 1 column, and the zip + city in 1 column.

That way, if the address line looks like this now, where it has no zip-code, then it will just be the city in the second column.

Like this:

ADDRESS , CITY

Thanks
0
Comment
Question by:magento
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 39815900
s/(\d+)\s+(\d+)/$1 , $2/
seems to work for your example, but I don't know if there may be other kinds of "ADDRESS" or other kinds of "ZIP CITY" for which another approach may be needed.
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39815903
So how do you know if it has a zip-code?

Are all the cities one word or there can be composite (Frankfurt-am-Main) or multiple word (New York) cities?
0
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
ID: 39815943
This accommodates for ZIP both 5 digit and 9 digit ones and also the absence of it.

echo 'Detmolder Str. 515 33605 Bielefeld' | perl -ne '/(.*) (?:(\d{5}(?:-\d{4})\s+))?(\w+\s?\w*)/; print "$1, $2 $3"'

Open in new window

0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 39816079
What countries are included in the addresses?  Wondering since that will affect detection of zip (some (most?) countries don't use 5-digit postal codes).

Are all the addresses in the format <street> <house number> <zip (optional)> <city>?  As others have asked, can the city be multiple words (such as New York)?
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question