Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch file to remove commas from a different file.

Posted on 2004-09-01
7
Medium Priority
?
1,230 Views
Last Modified: 2010-08-05
I need to run a command from a batch file that removes commas from a specified file.  Not too bothered what it does with them, either remove completely or replace with another character.

This is to stop user entered commas from messing up my format in a .CSV file.

Many thanks in advance!

Ian
0
Comment
Question by:IanWood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 11951377
Munge would probably be the easiest way to achieve this:
http://www.petri.co.il/download_free_reskit_tools.htm

If you're opposed to that idea, can you post a portion of your file along with what operating system you're using?
0
 

Author Comment

by:IanWood
ID: 11951490
I don't really want to start using 3rd party uliities to do this if I can help it.

The file is a bog standard text file (seperated by |'s) :-

H||Mrs|Elizabeth|Jones|7 wood Drive|Four Trees|Sutton|West Midlands|B74 5RD|01564 353 43334|liz@hotmail.com|Y|Mrs Elizabeth Jones|7 Wood Drive|Four Trees|Sutton|West Midlands|B74 5RD|Mrs Elizabeth Jones|7 wood Drive|Four Trees|Sutton|West Midlands|B74 5RD|VI|1234556578912345678|1102|1204||181927|280804|09:05|850|13|
D|26153|Sensitive Moisturising Body Lotion - 250ml|400|3|1200|
D|30064|30064|250|1|250|

I'm running XP, but any solution should ideally work on 2000 as well.

Thanks!
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 400 total points
ID: 11951640
Ok - XP is what I'm using, so this should work for you....

Before (I added a couple of commas to test):
H||Mrs|Elizabeth|Jones|7 wood, Drive|Four, Trees|Sutton|West, Midlands|B74 5RD|01564 353 43334|liz@hotmail.com|Y|Mrs Elizabeth Jones|7 Wood Drive|Four Trees|Sutton|West Midlands|B74 5RD|Mrs Elizabeth Jones|7 wood Drive|Four Trees|Sutton|West Midlands|B74 5RD|VI|1234556578912345678|1102|1204||181927|280804|09:05|850|13|
D|26153|Sensitive, Moisturising Body Lotion - 250ml|400|3|1200|
D|30064|30064|250|1|250|


After:
H||Mrs|Elizabeth|Jones|7 wood Drive|Four Trees|Sutton|West Midlands|B74 5RD|01564 353 43334|liz@hotmail.com|Y|Mrs Elizabeth Jones|7 Wood Drive|Four Trees|Sutton|West Midlands|B74 5RD|Mrs Elizabeth Jones|7 wood Drive|Four Trees|Sutton|West Midlands|B74 5RD|VI|1234556578912345678|1102|1204||181927|280804|09:05|850|13|
D|26153|Sensitive Moisturising Body Lotion - 250ml|400|3|1200|
D|30064|30064|250|1|250|


::-------begin code---------
@echo off
for /f "delims=" %%a in (test.txt) do call :process "%%a"
goto :eof

:process
set strData=%1
set strData=%strData:,=%
for /f "delims=" %%x in (%strData%) do echo %%x >> testnew.txt
::-------end code-----------

Not my prettiest coding, but effective.  Let me know if that will work for you...
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 2

Expert Comment

by:Drew Lake
ID: 11951723
I really don't know much about scripting but here is a site:  http://www.easydos.com/dosindex.html

I would think you would have to use the: IF, FIND, and DEL command in one string.  Good Luck and I hope this helps.
0
 

Author Comment

by:IanWood
ID: 11952129
SirBounty, That seems to work fine.  one thing, is there anyway to keep the original filename?  

Thanks!
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 11952176
If you're reading it line by line, then you'll have to export it into another file (I think munge will allow this).
For the code above though, simply add the following just before the goto :eof line:

if exist testnew.txt del test.txt
ren testnew.txt test.txt
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question