batch file to replace commas with tabs

November 30, 2010 at 15:10:36
Specs: Windows XP
I need to write a batch file that will take in a file and replace all commas with tabs.

See More: batch file to replace commas with tabs

Report •

November 30, 2010 at 16:57:50
To answer your question literally, here's the batch file:

@echo off
setlocal enabledelayedexpansion
for /f "delims=] tokens=1*" %%a in ('find /v /n "" ^<%1') do (
set line=%%b
if not "%line%" == "" set line=%line:,= %

But it sounds like you want to convert a comma-separated-values (.csv) file to a tab-separated values file. If that's the case, be careful. A simple comma-to-tab substitution doesn't always work. Some values contain commas or tabs. They are enclosed in quotes if they do. So you need a more sophisticated utility to deal with csv files properly. Have a google and you should find something. Alternatively, open the csv in Excel and save it as a tab-delimited text file.

Report •

November 30, 2010 at 19:37:23
Thanks so much for your solution and taking the time to post it. I will give it a try and will keep your caution in mind!! Again, Thanks!

Report •

December 1, 2010 at 09:39:32
By the way, if you haven't already realised, the input file is given to the batch file on the command line and you can redirect its output to >another file.

Report •
Related Solutions

Ask Question