Page 1 of 1
Adding Headers to a csv file?
Posted: 14 Feb 2012 03:34
by stylishjm
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?
Re: Adding Headers to a csv file?
Posted: 14 Feb 2012 03:56
by foxidrive
file.txt contains fields, one per line.
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"
Re: Adding Headers to a csv file?
Posted: 14 Feb 2012 04:02
by stylishjm
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.
Re: Adding Headers to a csv file?
Posted: 14 Feb 2012 04:02
by foxidrive
I was editing as you replied. See above.
Some characters could be a problem in fieldnames. Alphanumeric text is fine.
Re: Adding Headers to a csv file?
Posted: 14 Feb 2012 04:22
by stylishjm
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?
Posted: 14 Feb 2012 04:39
by stylishjm
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!