Following on from my earlier post regarding adding an extra column of information to a csv, I now need to get headers added to each column.
There are 40 columns, and have the header names in a .txt file, one per line.
Is there any easy way to add these in using a batch file?
Adding Headers to a csv file?
Moderator: DosItHelp
Re: Adding Headers to a csv file?
file.txt contains fields, one per line.
oldfile.csv contains the original data
newfile.csv is create with the header line and the data
oldfile.csv contains the original data
newfile.csv is create with the header line and the data
Code: Select all
@echo off
setlocal EnableExtensions EnableDelayedExpansion
for /f "delims=" %%a in ('type "file.txt"') do (
set "var=!var!,%%a"
)
set "var=%var:~1%"
echo %var%>"newfile.csv"
type "oldfile.csv">>"newfile.csv"
Last edited by foxidrive on 14 Feb 2012 04:02, edited 1 time in total.
Re: Adding Headers to a csv file?
Possibly a regular task, set up using windows scheduled tasks.
This file will sit on 150 computers so installing extra software is a no-go to be honest.
This file will sit on 150 computers so installing extra software is a no-go to be honest.
Re: Adding Headers to a csv file?
I was editing as you replied. See above.
Some characters could be a problem in fieldnames. Alphanumeric text is fine.
Some characters could be a problem in fieldnames. Alphanumeric text is fine.
Re: Adding Headers to a csv file?
foxidrive wrote:I was editing as you replied. See above.
Some characters could be a problem in fieldnames. Alphanumeric text is fine.
Thank you, will try that now.
Re: Adding Headers to a csv file?
foxidrive wrote:I was editing as you replied. See above.
Some characters could be a problem in fieldnames. Alphanumeric text is fine.
Worked perfectly, thank you!