computing
  • 0

How To Create a .Bat File That Will Delete Multi Columns?

  • 0

I have a folder containing 100+ .csv files, I want to delete multiple specific columns(ie same in every .csv) from every file and save it with same name and format as before. Manually I can do this by opening every file in excel; however this can take a looong time to accomplish.

I would like to be able to place an .bat file within this folder and run the .bat script so that it automatically deletes the identified columns for all of the .csv files within the mentioned folder.

Can any one help in creating such code…?

Specifically:
Can you show me how to create a similar .bat file that will delete the content(if any) of any columns that proceed column M…?

Please advise.

Share

1 Answer

  1. ::====== script starts here ===============
    ::
    :: Xcolumns.bat 2016-09-12 11:59:41.42
    @echo off > NEWFILE & setLocal enableDELAYedeXpansioN

    :main
    for /f “tokens=* delims= ” %%a in (‘dir/b *.csv’) do (
    call :sub1 %%a
    move NEWFILE %%~Na-NEW.CSV
    )
    goto :eof

    :sub1
    for /f “tokens=1-3,5-8 delims=,” %%i in (‘type %1’) do (
    echo.%%i, %%j, %%k, %%l, %%m, %%n, %%o
    ) >> NEWFILE
    goto :eof
    ::====== script ends here =================

    =====================

    M2 Get custom script or take private lessons

    • 0