Computing.Net > Forums > Programming > Add an Empty Column in CSV File

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Add an Empty Column in CSV File

Reply to Message Icon

Name: ebosco
Date: April 7, 2009 at 10:24:12 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: April 7, 2009 at 14:08:00 Pacific
Reply:

@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


0
Reply to Message Icon

Related Posts

See More


xcopy vs copy Batch file renaming



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Add an Empty Column in CSV File

Replace a column in a file using aw www.computing.net/answers/programming/replace-a-column-in-a-file-using-aw/18450.html

Batch script to copy column in CSV www.computing.net/answers/programming/batch-script-to-copy-column-in-csv-/16470.html

add or replace text in .txt file www.computing.net/answers/programming/add-or-replace-text-in-txt-file/18121.html