Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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?

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

I just realized that I missed one important question:
Will there be any blank fields?
ie. data,data,data,,data

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)

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.

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 %%aChange "newfile" as appropriate, it will append to existing files.

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

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 /?

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |