Computing.Net > Forums > Programming > Batch to insert column from one csv to anothe

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.

Batch to insert column from one csv to anothe

Reply to Message Icon

Name: temp_usr
Date: October 2, 2009 at 20:45:51 Pacific
OS: Windows XP
Subcategory: Batch
Tags: batch, csv
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: October 2, 2009 at 21:01:23 Pacific
Reply:

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


1

Response Number 2
Name: temp_usr
Date: October 2, 2009 at 21:24:57 Pacific
Reply:

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


0

Response Number 3
Name: Judago
Date: October 2, 2009 at 21:41:22 Pacific
Reply:

I just realized that I missed one important question:

Will there be any blank fields?

ie. data,data,data,,data


Batch Variable how to


0

Response Number 4
Name: temp_usr
Date: October 2, 2009 at 21:55:30 Pacific
Reply:

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)


0

Response Number 5
Name: Judago
Date: October 2, 2009 at 21:59:13 Pacific
Reply:

Excel isn't my thing, someone else will have to jump in.....


Batch Variable how to


0

Related Posts

See More



Response Number 6
Name: temp_usr
Date: October 2, 2009 at 22:00:53 Pacific
Reply:

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.


0

Response Number 7
Name: Judago
Date: October 2, 2009 at 22:10:50 Pacific
Reply:

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


1

Response Number 8
Name: temp_usr
Date: October 2, 2009 at 22:23:28 Pacific
Reply:

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


0

Response Number 9
Name: Judago
Date: October 2, 2009 at 22:31:07 Pacific
Reply:

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


1

Response Number 10
Name: temp_usr
Date: October 2, 2009 at 22:32:50 Pacific
Reply:

again thx alot


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Batch to insert column from one csv to anothe

Batch to read data and output www.computing.net/answers/programming/batch-to-read-data-and-output/13630.html

Cursor jump from one txt to another www.computing.net/answers/programming/cursor-jump-from-one-txt-to-another/9111.html

Moving files from one folder to diffrent www.computing.net/answers/programming/moving-files-from-one-folder-to-diffrent/18858.html