batch edit multiple csv

March 17, 2011 at 09:05:47
Specs: Windows XP
Hi there,

I have multiple (100's) comma delimited files with the extension .mnt.

Am I right in saying these are basically .csv files?

I need a batch script to change the numbers in 2 columns to something else.

Here is an example file:

Ve,s,500 ,500,2765,2685,195,130,99,62,220,130,290,210,94,77,190,147,125,95,600,0,600,0
Ve,s,10 ,100,2475,2375,195,130,95,60,195,138,390,300,84,67,170,135,142,113,600,0,600,0
Ve,s,5 ,50,2270,2175,225,160,105,62,200,150,450,380,81,66,175,135,150,123,600,0,600,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0

Some files have every line full like the top 3, others such as this only have three four or five.

The columns that need changing are the ones where 600 and 0 first appear. (4th and 3rd from the end)

600 needs changing to 3300
0 needs changing to 1400

Is this script possible?


See More: batch edit multiple csv

Report •

#1
March 17, 2011 at 18:30:18
Here's a Ruby for Windows script

c:\work> ruby -F","  -ane '$F[-4]=3300 if !/\*/ ;$F[-3]=1400 if !/\*/; puts $F.join(",")' file
Ve,s,500 ,500,2765,2685,195,130,99,62,220,130,290,210,94,77,190,147,125,95,3300,1400,600,0
Ve,s,10 ,100,2475,2375,195,130,95,60,195,138,390,300,84,67,170,135,142,113,3300,1400,600,0
Ve,s,5 ,50,2270,2175,225,160,105,62,200,150,450,380,81,66,175,135,150,123,3300,1400,600,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0
**,*,**********,0,0,0,0,0,0,0,0,0,0


Report •
Related Solutions


Ask Question