Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

perl or Simple Excel macro

Posted on 2014-01-28
4
331 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
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…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

856 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