Add an Empty Column in CSV File

April 7, 2009 at 10:24:12
Specs: Windows XP
Hi,

I have a follow CSV file:

ActionCode,OpCode,PassFail,Protocol,URL
Execute,OpenBrowserWMI,Pass,http,www.google.com
ActionCode,OpCode,PassFail
Execute,CloseBrowserWMI,Pass
ActionCode,OpCode,PassFail,Protocol,URL
Execute,OpenBrowserWMI,Pass,http,www.google.com
ActionCode,OpCode,PassFail
Execute,CloseBrowserWMI,Pass
ActionCode,OpCode,PassFail,Protocol,URL
Execute,OpenBrowserWMI,Pass,http,www.google.com
ActionCode,OpCode,PassFail
Execute,CloseBrowserWMI,Pass

and I need insert a new column bettween OpCode,PassFail in whole file not in the first line in around 1000 files.

for example:

ActionCode,OpCode,NEWCOLUMN,PassFail,Protocol,URL
Execute,OpenBrowserWMI,NEWCOLUMN,Pass,http,www.google.com
ActionCode,OpCode,NEWCOLUMN,PassFail
Execute,CloseBrowserWMI,NEWCOLUMN,Pass
ActionCode,OpCode,NEWCOLUMN,PassFail,Protocol,URL
Execute,OpenBrowserWMI,NEWCOLUMN,Pass,http,www.google.com
ActionCode,OpCode,NEWCOLUMN,PassFail
Execute,CloseBrowserWMI,NEWCOLUMN,Pass
ActionCode,OpCode,NEWCOLUMN,PassFail,Protocol,URL
Execute,OpenBrowserWMI,NEWCOLUMN,Pass,http,www.google.com
ActionCode,OpCode,NEWCOLUMN,PassFail
Execute,CloseBrowserWMI,NEWCOLUMN,Pass

Look the lines, it has diferent numbers of parameters but the first three always are the same.

Anybody knows how to I resolve this question.

Thanks a lot BOSCO


See More: Add an Empty Column in CSV File

Report •


#1
April 7, 2009 at 14:08:00
@echo off & setlocal EnableDelayedExpansion
for %%j in (*.csv) do (
  set /P header=< %%j
  echo.!header!> %%~nj.new
  for /F "skip=1 tokens=1,2,* delims=," %%a (%%j) do (
    echo.%%a,%%b,,%%c>> %%~nj.new
  )
)
:: End_Of_Batch


Report •
Related Solutions


Ask Question