computing
  • 4

Batch File To Replace Commas With Tabs

  • 4

I need to write a batch file that will take in a file and replace all commas with tabs.

Share

1 Answer

  1. 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:,= %
    echo.!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.

    • 0