473,765 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trimming extra spaces from large DB file

Hi, I need some advice on what to do. I have this MySQL insert file,
with about 30,000 records. One of the datafields has names in it. When
this list was put together, apparently there was extra space formatting
inserted at the end of each name. I want to remove these, so for
example:
INSERT INTO `table_one` VALUES ('John Doe ', 1);
INSERT INTO `table_one` VALUES ('Jane Doe ', 2);
INSERT INTO `table_one` VALUES ('Baby S. Doe ', 3);

I want:

INSERT INTO `table_one` VALUES ('John Doe', 1);
INSERT INTO `table_one` VALUES ('Jane Doe', 2);
INSERT INTO `table_one` VALUES ('Baby S. Doe', 3);

I was thinking some kind of script could be put together to trim the
extra spaces out. I have this entire insert list as a text file and can
re-insert it, or leave it in the DB and run queries against it. What
complicates this for me is some of the name fields have middle names,
some do not. Maybe something to remove all spaces greater than one on a
first pass, and then on a second pass trim the extra space at the end
only. That is what I think of in theory - but have no idea how to
create such script. Can anyone help? I would be very much appreciated.

Sincerely,

Alex

Jul 17 '05 #1
1 1932
MySQL has a trim function so I think the easiest way would be to load the
file into MySQL and then:

UPDATE table_one SET `name` = TRIM(`name`);

Replace `name` with whatever the column name is.

Best Regards,

Peter Albertsson
<Ra*********@ho tmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Hi, I need some advice on what to do. I have this MySQL insert file,
with about 30,000 records. One of the datafields has names in it. When
this list was put together, apparently there was extra space formatting
inserted at the end of each name. I want to remove these, so for
example:
INSERT INTO `table_one` VALUES ('John Doe ', 1);
INSERT INTO `table_one` VALUES ('Jane Doe ', 2);
INSERT INTO `table_one` VALUES ('Baby S. Doe ', 3);

I want:

INSERT INTO `table_one` VALUES ('John Doe', 1);
INSERT INTO `table_one` VALUES ('Jane Doe', 2);
INSERT INTO `table_one` VALUES ('Baby S. Doe', 3);

I was thinking some kind of script could be put together to trim the
extra spaces out. I have this entire insert list as a text file and can
re-insert it, or leave it in the DB and run queries against it. What
complicates this for me is some of the name fields have middle names,
some do not. Maybe something to remove all spaces greater than one on a
first pass, and then on a second pass trim the extra space at the end
only. That is what I think of in theory - but have no idea how to
create such script. Can anyone help? I would be very much appreciated.

Sincerely,

Alex

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4832
by: Generic Usenet Account | last post by:
I have worked out the following implementation for trimming the leading and trailing whitespace characters of a string (I am surprised not to see these as member functions). Am I doing it correctly, or is there a better way to do it? Thanks, Gus //////////// Source code begin /////////////////////
5
4078
by: Marco Gallo | last post by:
I've been trying to get rid of extra spaces in a table that I created with addresses in it. For instance in a field called TEST, I got the following address: " 1 main st Apt A " First I tried to use the "trim", "ltrim" and "rtrim" functions, these functions did work, but only for those spaces at the beginning and at
13
3672
by: john_g83 | last post by:
have a bit of c code that is ment to take a string (that may or may not have spaces before or after the string) i.e. " stuff ", and trims off the whitespace before and after. Code: char *trim (char *str, char ch) { char *first, *last; int count;
3
2472
by: leeps_my | last post by:
I'm thinking of using "resize-to-size" to do the trimming: aVector.resize( aVector.size( ) ); I'm wondering why Scott Meyers was recommending "swap trick" instead, since the trick involves construction and destruction of a temporary, and might still leave some excess capacity in the vector.
135
7517
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about which is better. It has become what's known as “religious war” — a heated fight over trivia. In this essay, i like to explain what is the situation behind it, and which is proper.
5
1932
by: dw | last post by:
hello - first, let me state that i am an Asp.Net rookie. here is the situation: i have a page that looks good in the vs.net designer, but when the page renders there are extra amounts (vertically) of space between controls. i have all of the controls in a table, to help line them up, and I have reviewed the html to verify that there are no extra spaces or paragraphs or breaks between the controls. however, when i run the web site,...
7
1837
by: veg_all | last post by:
I am looking for a simple way to keep my log files from growing too large. Basically I would want something that truncates the off first 25 kb of a 100kb log file. I could do something with reading in the file twice, first to determine number of lines. Then a second time to write a copy of the reduced log file. Any simpler workarounds?
2
10473
code green
by: code green | last post by:
I am trying to write a simple function that will take a string containing an address line or business name and return it nicely formatted. By this I mean extra spaces removed and words capitalised. I also wish it to be legal XML.. The result string is further sent to another function to check the names and addresses don't appear on a blacklist which is why the extra spaces need removing. This is my test function so far function...
2
4704
by: Jibran | last post by:
I need some help with extra spaces in HTML form. There is a big white space appearing at the center of the HTML form that I am designing even though there is no <br> tags been used: http://i116.photobucket.com/albums/o9/Jibran82/Pic1.jpg The html code is below: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type"
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.