Page 1 of 1

Removing All Spaces from CSV

Posted: 20 Apr 2012 12:10
by gsanders32
I need a little help with a csv file. I need to remove all the spaces in the file. I would like to do this in a batch file, so I can use windows task scheduler to automate the removal of the spaces.

Example
41712, 1200, 113.6539, 63.724998, 12.974346
41712, 1215, 113.724701, 63.612499, 13.04028
41712, 1230, 113.770203, 63.724998, 13.07691
41712, 1245, 113.805603, 63.724998, 13.11354
41712, 1300, 113.837601, 63.612499, 13.142844

Re: Removing All Spaces from CSV

Posted: 20 Apr 2012 13:55
by trebor68
If only the value have numbers then is this easy.

Code: Select all

@echo off
set oldfile=oldfile.csv
set newfile=newfile.csv
for /f "tokens=1-5" %%a in (%oldfile%) do echo %%a%%b%%c%%d%%e >>%newfile%

Re: Removing All Spaces from CSV

Posted: 20 Apr 2012 14:57
by tonysathre

Code: Select all

@echo off & setlocal enabledelayedexpansion
set in=file.csv
set out=file2.csv
for /f "tokens=*" %%i in ('type %in%') do (
   set line=%%i
   >>%out% echo !line: =!
)

Re: Removing All Spaces from CSV

Posted: 20 Apr 2012 14:59
by gsanders32
Thank you very much that worked great.

Re: Removing All Spaces from CSV

Posted: 20 Apr 2012 16:13
by Squashman
One of my favorite uses of the TR command from my days of being a Linux admin. They have a port of it for windows.

Re: Removing All Spaces from CSV

Posted: 20 Apr 2012 20:16
by foxidrive
Also, a change utility will do it simply. Bruce Guthrie wrote a swag of 16 bit freeware utilities including change.exe - they only work with short filenames but are still effective.

And SED is a good contender too.

The batch script is good too though in this case.