I typoed an extra "/" at the end of the code
Main Topics
Browse All TopicsI have a .csv file to import into a table in a MSSQL database. The problem is the .csv file is just one columns with about 4 different fields all separted with a series of spaces.
Example
Jon Doe NUll 12333 S1548
Mary Jane Miii 15483 E22566
and so on.
I am trying to remove the white spaces but when I use the trim feature in the DTS package I lose some data, IS there anyway to do this and get all the data at the same time?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Ah....I didnt see the spaces between the first name and the last name. So that simple one-liner goes doesnt work. Also, this is only one column that we are talking about here and not the whole file. The first column can be obtained using Text::CSV.
Is there always only one space between first name and last name, and always more than one space between fields?? Is there any special characters there??
In other words, how do we differentiate betwen the space in the Name, and the space between the fields.
You can use this:
perl -i.bak -pe 's/\s{3,}/\|/g' <filename>
Replace <filename> with the actual filename you want changed. This will create a backup file, with the same name as <filename> but with .bak added.
The 3 means at least three spaces will be considered the seperator. This works fine on your example, but if your actual data is different, you can change the 3 to another number.
It is a command line perl program. Instead of the perl code being placed in a file, you run it directly from the command line.
What it means:
perl Use the perl interpreter to run the code
-i.bak Edit the file in-place (use the named file as both input and output)
and create a backup with the extension .bak
-p assume "while (<>) { ... }" loop around program
print line at end of while loop
-e The actual perl code. It is placed in quotes so the shell doesn't do anything
unix shells use single-quotes, windows shell use double-quote
filename The filename to edit
So, in long form, it would be this:
Business Accounts
Answer for Membership
by: manav_mathurPosted on 2008-02-06 at 06:18:11ID: 20832051
But remember, things get dicey when some of your fields are null.
Select allOpen in new window