Removing All Spaces from CSV

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
gsanders32
Posts: 2
Joined: 19 Apr 2012 21:53

Removing All Spaces from CSV

#1 Post by gsanders32 » 20 Apr 2012 12:10

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

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: Removing All Spaces from CSV

#2 Post by trebor68 » 20 Apr 2012 13:55

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%

tonysathre
Posts: 14
Joined: 20 Mar 2012 10:07

Re: Removing All Spaces from CSV

#3 Post by tonysathre » 20 Apr 2012 14:57

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: =!
)
Last edited by tonysathre on 20 Apr 2012 15:02, edited 2 times in total.

gsanders32
Posts: 2
Joined: 19 Apr 2012 21:53

Re: Removing All Spaces from CSV

#4 Post by gsanders32 » 20 Apr 2012 14:59

Thank you very much that worked great.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Removing All Spaces from CSV

#5 Post by Squashman » 20 Apr 2012 16:13

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Removing All Spaces from CSV

#6 Post by foxidrive » 20 Apr 2012 20:16

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.

Post Reply