CSV file editing through BATCH file

September 15, 2010 at 03:41:02
Specs: Windows XP
hi!!!!!!!!!!! guys

i have a csv file of following format!!!

ALPHA TANGO CHARLEE GRAVO
aa bb cc dd
aa dd ee ff
aa gg jj jj
aa ff tt kk

i want to change the format in followng manner


ALPHA TANGO CHARLEE GRAVO
aa bb cc dd
dd ee ff
gg jj jj
ff tt kk


i want to remove aa from next all fields and those fields should remain blank.

any suggesstions to make these changes through batch script

thanks a lot!!!!!!!!!!!!


See More: CSV file editing through BATCH file

Report •


#1
September 16, 2010 at 03:51:38
Hard to work out what you want. You say you have a csv file then show data without a single comma. Do you want to edit the .CSV file complete with comma separators or do you want to edit the file shown without commas?

Report •

#2
September 16, 2010 at 20:12:53
my original file is as follows


NODE, Protocol,Process ID,Process Name,Local Address,Local Port
abc, TCP,0,SYSTEM,192.168.2.105,4457
abc, TCP,4,SYSTEM,192.168.2.105,139
abc, TCP,4,SYSTEM,0.0.0.0,445
abc, TCP,4,SYSTEM,192.168.159.1,139


i want to remove abc... from second field onwards

NODE, Protocol,Process ID,Process Name,Local Address,Local Port
abc, TCP,0,SYSTEM,192.168.2.105,4457
, TCP,4,SYSTEM,192.168.2.105,139
, TCP,4,SYSTEM,0.0.0.0,445
, TCP,4,SYSTEM,192.168.159.1,139

thank u


Report •

#3
September 17, 2010 at 02:03:17
Try this:

@echo off>output.csv
cls
setlocal enabledelayedexpansion

set counter=1

for /f "tokens=*" %%1 in (input.csv) do (
    set inline=%%1

    if !counter! gtr 2 (set inline=!inline:~3!)

    >>output.csv echo !inline!
    set /a counter+=1
)

If that won't work because the variable in column 1 is not fixed at three bytes as you show, try the following:

@echo off>output.csv
cls
setlocal enabledelayedexpansion

set counter=1

for /f "tokens=1* delims=," %%1 in (input.csv) do (
    
    if !counter! gtr 2 (
       >>output.csv echo ,%%2
       ) else (
       >>output.csv echo %%1,%%2
       )

    set /a counter+=1
)



Report •

Related Solutions

#4
September 17, 2010 at 22:54:15
thanks very much

Report •


Ask Question