Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bat script - remove space in a file 1

Status
Not open for further replies.

pho01

Programmer
Mar 17, 2003
218
US
Does anybody know how to remove space in a file using dos command in a .bat script?

Basically the original log file looks like this:
1; 1; 246; 231;master
1; 1; 10; 10;modeldev
1; 1; 180; 177;MSDBData
1; 1; 20; 20;pubs
1; 1; 28; 26;SSODB
1; 1; 128; 16;tempdev

and i need to remove all spaces so it would look this:
1;1;246;231;master
1;1;10;10;modeldev
1;1;180;177;MSDBData
1;1;20;20;pubs
1;1;28;26;SSODB
1;1;128;16;tempdev

This is easily done in unix, but i have issues doing that in windows. Thanks lots for your suggestions/help.
 
You can do this in wordpad using the replace feature. Edit menu - Replace [spacebar](actually hit the spacebar) and replace with "nothing," meaning don't enter anything in the box. Hit replace all button and the spaces are removed. If they turn out too be tabs and not spaces, the just use the tab key.

If you need to script it, I know that you can call command exe's in batch or VBScript. I don't have code to do what you are asking, but check out VBScript forum. In VB you do not have to call wordpad in your script, there are methods to edit the file.
 
Should be easy:

Code:
FOR /f "tokens=1,2,3,4" %a in (logfilename.log) do @echo %a%b%c%d>>newlogfilename.log

in a batch file, double the percent, for example:

Code:
@echo off
FOR /f "tokens=1,2,3,4" %%a in (logfilename.log) do @echo %%a%%b%%c%%d>>newlogfilename.log
ren logfilename.log logfilename.log.old
ren newlogfilename.log logfilename.log

Also, I would only to a file/replace from a pure text editor like notepad. I don't trust wordpad, even when saving as text to save it without throwing in potentially unwanted extra junk and or stripping the format you really want.

Besides, that might not be spaces but instead, tabs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top