Populating a new column with current date in a csv file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zimmermand
Posts: 3
Joined: 09 Feb 2015 10:28

Populating a new column with current date in a csv file

#1 Post by zimmermand » 09 Feb 2015 11:10

I have a csv file that currently has 3 columns and over 7000 rows. I need to create populate a 4th column with the current date (ex: 02/09/2015) for all of the rows. Any help is appreciated.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Populating a new column with current date in a csv file

#2 Post by Squashman » 09 Feb 2015 12:50

assuming your date variable is in this format.

Code: Select all

H:\>echo %date%
Mon 02/09/2015

You can use this.

Code: Select all

@echo off
set tdate=%date:~4%

FOR /F "delims=" %%G IN (myfile.csv) DO >>newfile.csv echo %%G,%tdate%

There are ways to make the date regional independent should it be in a different format.

zimmermand
Posts: 3
Joined: 09 Feb 2015 10:28

Re: Populating a new column with current date in a csv file

#3 Post by zimmermand » 09 Feb 2015 14:09

This worked...thank you. I am very new to scripts and now need to do this for a 2 column csv. Is it the 4% that tells it to put it in the 4th column?

zimmermand
Posts: 3
Joined: 09 Feb 2015 10:28

Re: Populating a new column with current date in a csv file

#4 Post by zimmermand » 09 Feb 2015 14:43

Disregard my 2nd reply...it works great! Thank you.

Post Reply