Apolyton Archive  |  Preserved copy of the Apolyton Civilization Site and its forums as they stood in September 2005. Read-only; nothing here can be posted to or replied to.  |  Forum index |  About this archive |  The 1998–2001 UBB forums
Today on Apolyton WARDELL INTERVIEW PROMO A.C.S. HISTORY CHAPTER 4 GET CIV4 /w FREE PLUS! A.C.S. PHOTO GALLERY GET A.O.M. V1.1
Apolyton Civilization Forums
main| civ2| civ3| civ4| smac| ctp2| ron| moo3| galciv| galciv2| alt| about|
ApolytonPLUS | register | search | faq | new posts | pm (-/-) | upload | members
hall of fame new! | civgroups | civgroups news | interviews | the column | radio | chat | directory | news | store | PLUS
Apolyton Civilization Forums : Powered by vBulletin version 2.0.3 Apolyton Civilization Forums > Miscellaneous > Archive > Off-Topic-Archive > Programmers please read.
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!

bottom of page
  
Author
Thread    < Last Thread     Next Thread > Post New Thread     Post A Reply
DrSpike is offline DrSpike
Deity
Enthusiastic member of Apolyton
Sep 2001
time: 05:30
  Old Post 01-09-2003 21:37
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
Programmers please read. Help yourself to an AD-FREE life

I have an annoying problem with my latest piece of research, which is an empirical study (please don't stop reading - I'm getting to the programming part ).

I have a main dataset which attaches a postcode (like zip code) district to each individual. I then have other datasets which I will map into the main one. Unfortunately many of the postcodes (which are saved as strings) in the main set have spaces at the start, and since [(space)B1] is not equal to B1 I can't merge my sets.

Now I have converted the string to an ascii file, and of course I can remove the spaces and reconvert back into my econometric package. But there are about 100,000 offending spaces (stop laughing, it's not funny!). Glancing at the rest of the data it seems there will be further space related problems.

Attached is a .txt file, with a small sample of the observations on individual lines between quote marks. Essentially I need an automated way to remove all spaces within each set of quote marks, so that "(space)(space)B1" becomes "B1"

It's such a trivial problem I'm sure a programmer can suggest a solution straight away. I hope so anyway.

Attachment: juvos.txt
This has been downloaded 10 time(s).

Pekka is offline Pekka
Chieftain
em seu burro dos pais!
Feb 2002
time: 07:30
  Old Post 01-09-2003 21:40
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Browse Apolyton AD-FREE

I was going to say 'how are you going to learn if you just want solutions straight up', but then again I realized I might get into a problem I can't solve at all, and I might ask help here, so you know.. I'd be digging my own grave .

mrmitchell is offline mrmitchell
King

Donate to the Red Cross

Sep 2002
time: 23:30
  Old Post 01-09-2003 21:47
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations: Deluxe Edition

Don't most word processors have a "Find and Replace" feature? Would that help at least a little?

geeslaka is offline geeslaka
Prince
of the purple hand
Jun 2003
time: 22:30
  Old Post 01-09-2003 21:48
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations

Post the entire thing with a fixed example line. I'll use Emacs's query string replace to remove the spaces. I just tested on juvos.txt and it worked.

DrSpike is offline DrSpike
Deity
Enthusiastic member of Apolyton
Sep 2001
time: 05:30
  Old Post 01-09-2003 21:53
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Support Apolyton, buy Alpha Centauri

Find and replace I did think of, but there are still 3,000 different postcodes in each set. Geeslaka's comment looks more promising.

Geeslaka: As I said the dataset is huge (even the text file with all the observation on this variable is 2.5MB) so I can't attach it. Also I will face more space related problems with the sets I am mapping in, I am sure.

Hence can you explain this method of yours? Or is it something a humble economist will not be able to do?

MichaeltheGreat is offline MichaeltheGreat
Apolyton Grand Executioner
mooning the house that Ruth built.
Oct 1999
time: 21:30
  Old Post 01-09-2003 21:55
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Increase Your PM Length

quote:
Originally posted by mrmitchell
Don't most word processors have a "Find and Replace" feature? Would that help at least a little?


That would be the simplest way - just import the file into word, trim out spaces (replace "(space) with " ) and be done with it quicker than you could write a chunk of code to do the same thing.

If this was going to be a constant problem with many new data sources, and the program had reusability, then I'd code something to clean up those files.

Sirotnikov is offline Sirotnikov
King
<--- Yes, It's a "kitty" in a boot.
Feb 2000
time: 07:30
  Old Post 01-09-2003 21:56
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Got spare money?

If you wish I can write a short pascal prog to fix it.

MichaeltheGreat is offline MichaeltheGreat
Apolyton Grand Executioner
mooning the house that Ruth built.
Oct 1999
time: 21:30
  Old Post 01-09-2003 21:56
Edit/Delete Message Reply w/Quote
#8 Report this post to a moderator
Help yourself to an AD-FREE life

quote:
Originally posted by DrSpike
Find and replace I did think of, but there are still 3,000 different postcodes in each set. Geeslaka's comment looks more promising.

Geeslaka: As I said the dataset is huge (even the text file with all the observation on this variable is 2.5MB) so I can't attach it. Also I will face more space related problems with the sets I am mapping in, I am sure.

Hence can you explain this method of yours? Or is it something a humble economist will not be able to do?


What language / DB are you using?

Sirotnikov is offline Sirotnikov
King
<--- Yes, It's a "kitty" in a boot.
Feb 2000
time: 07:30
  Old Post 01-09-2003 21:57
Edit/Delete Message Reply w/Quote
#9 Report this post to a moderator
Inflate your Upload Space

Or one could use emacs if he has such a thing.

geeslaka is offline geeslaka
Prince
of the purple hand
Jun 2003
time: 22:30
  Old Post 01-09-2003 22:04
Edit/Delete Message Reply w/Quote
#10 Report this post to a moderator
Increase Your PM Length

M-x query-replace-regexp
Is each line simple " B2", or is there more after that? If you want to remove all spaces, not just the leading ones, MtG's suggestion will work.

DrSpike is offline DrSpike
Deity
Enthusiastic member of Apolyton
Sep 2001
time: 05:30
  Old Post 01-09-2003 22:05
Edit/Delete Message Reply w/Quote
#11 Report this post to a moderator
Increase the size of your Attachments

quote:
Originally posted by MichaeltheGreat


What language / DB are you using?


I should reiterate I am an economist/econometrician.

What is emacs?

DrSpike is offline DrSpike
Deity
Enthusiastic member of Apolyton
Sep 2001
time: 05:30
  Old Post 01-09-2003 22:10
Edit/Delete Message Reply w/Quote
#12 Report this post to a moderator
Suffering from ads?

quote:
Originally posted by geeslaka
M-x query-replace-regexp
Is each line simple " B2", or is there more after that? If you want to remove all spaces, not just the leading ones, MtG's suggestion will work.


Some have 2 leading spaces, and some 1. Other have spaces in the middle, which I may or may not want to remove, I'm not sure yet.

Sirotnikov is offline Sirotnikov
King
<--- Yes, It's a "kitty" in a boot.
Feb 2000
time: 07:30
  Old Post 01-09-2003 22:10
Edit/Delete Message Reply w/Quote
#13 Report this post to a moderator
Tired of ads?

it's allows for very advanced and configuarble search and replace queries.

But you have to have unix or some unix-like tool to use it.

geeslaka is offline geeslaka
Prince
of the purple hand
Jun 2003
time: 22:30
  Old Post 01-09-2003 22:15
Edit/Delete Message Reply w/Quote
#14 Report this post to a moderator
Support Apolyton, buy GURPS/ Alpha Centauri

Since you do not have Emacs and it would take longer to install it, email the text file to me with one line fixed. I just emptied my box so it should fit.

DrSpike is offline DrSpike
Deity
Enthusiastic member of Apolyton
Sep 2001
time: 05:30
  Old Post 01-09-2003 22:27
Edit/Delete Message Reply w/Quote
#15 Report this post to a moderator
Put an end to popups!

Geeslaka: Thanks, I will certainly take up that offer if a find and replace will not work. However there will probably be more requests later.

Let's assume for a second I want to remove all the spaces, no matter where they are. It has been suggested that MtG's idea would work in this case, but how do you remove the spaces with one find and replace?

Example:

"(space)(space)B1" must become "B1"
"(space)B12" must become "B12"

There may be spaces in the second/third position or both as well for some codes.

I can see how to replace "(space)(space)B1" with "B1" but I have thousands of finds and replace to do in that case, right?

geeslaka is offline geeslaka
Prince
of the purple hand
Jun 2003
time: 22:30
  Old Post 01-09-2003 22:33
Edit/Delete Message Reply w/Quote
#16 Report this post to a moderator
Support Apolyton, buy Civilization: The Boardgame

If you can find something with regex find and replace, use this for the regex.
(space)*B.*
* is a wildcard that means "zero or more of the previous character"
. is a wildcard that means "any character"
That will match both of those cases.

Proteus_MST is offline Proteus_MST
Prince

Dec 2001
time: 06:30
  Old Post 01-09-2003 22:34
Edit/Delete Message Reply w/Quote
#17 Report this post to a moderator
Put an end to popups!

Just expot it into Access,
write a small VBA Solution and then reconvert it into Text

If it is in a compatible Format to convert it (i.e. all Fields are separated, for example by Commas or by Tabs) there should be no Problem

DrSpike is offline DrSpike
Deity
Enthusiastic member of Apolyton
Sep 2001
time: 05:30
  Old Post 01-09-2003 22:35
Edit/Delete Message Reply w/Quote
#18 Report this post to a moderator
Put an end to popups!

Hold that..........I can see how 2 separate replace "(space) with " can solve the problem for the main 2 cases. I can also see now that removing all spaces with find and replace is easy (I didn't think before it woudl work).

If there is a more complex problem I'll bug Geeslaka.

Cheers all.

Doc

Last edited by DrSpike on 01-09-2003 at 22:43

geeslaka is offline geeslaka
Prince
of the purple hand
Jun 2003
time: 22:30
  Old Post 01-09-2003 22:45
Edit/Delete Message Reply w/Quote
#19 Report this post to a moderator
Enter the AD-FREE zone

* waits to be bugged *
It's the monday after Labor Day so I have no school and lots of better things to do that need ignoring.

Edit: typo

Last edited by geeslaka on 01-09-2003 at 23:17

DrSpike is offline DrSpike
Deity
Enthusiastic member of Apolyton
Sep 2001
time: 05:30
  Old Post 01-09-2003 22:50
Edit/Delete Message Reply w/Quote
#20 Report this post to a moderator
Lose 30 kilos (of popups)

Well I've finished for the day now. I'll check tomorrow and see if I need a "clever" solution. Right now I think the blunt method will work. I had no idea find and replace would recognise and remove (space) without any unwanted side-effects, which of course there would be in a normal setting - I was envisaging doing a find and replace for each separate code.

And I said "bug". There are other people around here who can help you with your other problem.

pchang is offline pchang
King
Cupertino?
Aug 1999
time: 05:30
  Old Post 01-09-2003 23:10
Edit/Delete Message Reply w/Quote
#21 Report this post to a moderator
Dr. Spike Support Apolyton buy from Amazon

If you need to remove leading spaces only, then you will need to install some more software on your machine. There are a number of choices:

1) Emacs for PC
2) Perl or some other scripting language (one of us can send you an appropriate script to run)
3) Customer program (one of us can write a simple program and compile it to a windows executable and send it to you - this may require installation of a dll too).

Mercator is offline Mercator
King
Sorekara no Nanimo
Jan 1970
time: 06:30
  Old Post 01-09-2003 23:22 Visit Mercator's homepage!
Edit/Delete Message Reply w/Quote
#22 Report this post to a moderator
Support Apolyton, buy Civilization III: Complete

Open file in Word, select all, turn into list, turn list off again... Tadaa! All leading spaces are gone.

Or get a decent program that can do regular expressions.

Edit: major crosspost, and I didn't see there was a quotation mark before it... oh well

Last edited by Mercator on 01-09-2003 at 23:35

DanS is offline DanS
Emperor
Kickball Capital of the World
Jan 1970
time: 00:30
  Old Post 01-09-2003 23:58 Visit DanS's homepage!
Edit/Delete Message Reply w/Quote
#23 Report this post to a moderator
Support Apolyton, pre-order Civilization IV

Spike: What you are looking for is just one line of code. I would ship it off to geeslaka, because of what pchang mentions. It shouldn't take him but 5 minutes to do.

DrSpike is offline DrSpike
Deity
Enthusiastic member of Apolyton
Sep 2001
time: 05:30
  Old Post 02-09-2003 03:24
Edit/Delete Message Reply w/Quote
#24 Report this post to a moderator
Suffering from ads?

As I said thanks all, but I think I can use MtG's suggestion. If I need something more clever I will ask one of the people who have kindly offered to help out.

Urban Ranger is offline Urban Ranger
Apolyton Duke of Off-Topic

Donate to the Red Cross
The City State of Noosphere, CPA special envoy
May 1999
time: 13:30
  Old Post 02-09-2003 15:04
Edit/Delete Message Reply w/Quote
#25 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations: Deluxe Edition

In order of preference:

1. Perl, awk or any similar tools that support regex
2. BASIC (nice built-in string handling capabilities)
3. Turbo Pascal/Delphi/Klylix (very handy, not quick-and-dirty for this situation, though)

Urban Ranger is offline Urban Ranger
Apolyton Duke of Off-Topic

Donate to the Red Cross
The City State of Noosphere, CPA special envoy
May 1999
time: 13:30
  Old Post 02-09-2003 15:06
Edit/Delete Message Reply w/Quote
#26 Report this post to a moderator
Got spare money?

If you are interested, you can investigate Cywin for future uses

  < Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:30.
Apolyton Time is 00:30.
    top of page
Rate This Thread:
archivepost
Forum Jump:
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
 




Contact Us - Apolyton Civilization Site - Support Us!

Building a better Apolyton through better information. Click here and take our poll!
Non-US visitors, click here!

Powered by: vBulletin Version 2.0.3
Copyright ©2000, 2001, Jelsoft Enterprises Limited.

Page generated in 0.0555 seconds (92.32% PHP - 7.68% MySQL) with 31 queries
Page Loading Time:

Support Apolyton: Amazon USA | Amazon UK | Amazon DE | Amazon FR |
Support Apolyton and get FREE PLUS, Buy from Chips&Bits: Galactic Civilizations | Galactic Civilizations: Deluxe Edition | Call to Power 2 | Civilization: The Boardgame | GURPS/ Alpha Centauri | Alpha Centauri | Civilization IV | Civilization III: Complete |


Front Page | Civilization IV | Civilization III | Civilization II | Call to Power II | Alpha Centauri | Master of Orion III
Rise of Nations | Galactic Civilizations | Galactic Civilizations II | Misc
Alt.Civs | Civ I | C:CtP I | About | News | Directory | Apolyton Store | Forums | Chat | Columns | Interviews | Newsletter
Scenario League | CSC | Clash of Civs | Spanish Site | CtP Maps | Cradle of Civ | WesW's Ctp1/2 Site | Civ3 Haven

apolyton.net | apolyton.com | civilization2.net | civilization3.net | civilization4.net | civilizationiv.info | calltopower.net | galciv.net | galciv2.net | moo3.net