Batch to insert column from one csv to anothe

October 2, 2009 at 20:45:51
Specs: Windows XP
I am in need of a batch file, that can copy column(B) in an csv file (1.csv) and paste in in colomn(H) in another (Excel, but can convert to csv), but as H2 and not H1 as i have a header.

1.csv
Date 1 DATA DATA
Date 2 DATA DATA
Date 3 DATA DATA
2.csv
A B C D E F G Pasted here I J K L



See More: Batch to insert column from one csv to anothe

Report •


#1
October 2, 2009 at 21:01:23
You will have to be a little more specific.

1.does column "H" already have data that needs to be overwritten or is the new data to be inserted pushing the old data to the right?

2. Do both files have headers? How many lines are these headers? which one is to be kept?

3. Do these files contain "(double quote character), !, &, |, < or >?

4. You say they are csv's does any of the data contain comma's that aren't delimiters - i.e. inside double quotes?


Batch Variable how to


Report •

#2
October 2, 2009 at 21:24:57
column H, would most likely be overwritten, and no pushing as the other columns have important data. no only 1 file has th header, the 2nd file the needs pasting has headers all across, and no special characters, maybe just the extension name of a file. ex file1.doc

Report •

#3
October 2, 2009 at 21:41:22
I just realized that I missed one important question:

Will there be any blank fields?

ie. data,data,data,,data


Batch Variable how to


Report •

Related Solutions

#4
October 2, 2009 at 21:55:30
hmm i just realized i wont be able to use csv, since i require the vlookup function from excel, and i thought the csv could save the formulas (vlookup) but it doesnt. so here is what im thinking

1.-Maybe there would be a way to auto load the .csv to a specific column to excel (xls), which in this case makes it a lot easier to transfer column(b) from file 1.csv into a new blank csv file.

so i guess what i am now asking is just to get column(B) and creating a new file with only that column as colum(A)


Report •

#5
October 2, 2009 at 21:59:13
Excel isn't my thing, someone else will have to jump in.....


Batch Variable how to


Report •

#6
October 2, 2009 at 22:00:53
well what im asking im sure you could do, just tell me how to copy column(B) from file 1.csv, to a new file or already existance file 2.csv.

Report •

#7
October 2, 2009 at 22:10:50
Well if you only want that one column in a new file or appended to an existing it's quite easy provided that the first and second columns in 1.csv always have data and what you posted above holds true.

for /f "tokens=2 delims=," %%a in (1.csv) do >> newfile echo %%a

Change "newfile" as appropriate, it will append to existing files.


Batch Variable how to


Report •

#8
October 2, 2009 at 22:23:28
Thanks alot! this worked, do you mind explaining what the commands mean, the /f i assume tokens=2 means the 2nd column with the delimiter of "," the %%a

Report •

#9
October 2, 2009 at 22:31:07
For /f is a loop that iterates over lines of text, every line of text it is split up on the tokens and delimiters(which you guessed correctly about), and possibly other options if specified.

The text is then added to the specified variable, in this case %%a(can be most characters but is case sensitive) and the command after "do" is executed. The variable is only valid in the "do" command(or code block).

For more detailed info: start > run > cmd > for /?


Batch Variable how to


Report •

#10
October 2, 2009 at 22:32:50
again thx alot

Report •


Ask Question