Batch to fill a csv column with text

May 6, 2009 at 09:33:53
Specs: Windows XP
I have a csv file that I need to send weekly to a Raiser's Edge DB to sync e-mail OptOuts. One column is "DoNotMail" and is blank. I need to fill all the rows with "Yes" before importing the csv to the RE DB.

Thank You, This Forum is great!

See More: Batch to fill a csv column with text

Report •

June 3, 2009 at 09:59:45
Try this. (Assumptions: File path is "X.csv". Column 2 is "DoNotMail". There can be empty rows and empty columns. Columns are comma separated and can contain spaces, quotes, etc.)

# Script: FillColumn.txt
# Input arguments file (string) column (integer), value (string)
var int file, column ; var str value

# Set column separator to comma.
set $wsep = ","

# Read file.
var str data, new_data ; cat $file > data

# Read rows one by one
while ($data <> "")
# Read next row.
var str row ; lex -e "1" $data > $row

# Insert value into column.
win -e makestr(int($column)) $value $row

# Put row into $new_data.
echo ($row+"\n") >> $new_data

# Write $new_data to file.
echo $new_data > { echo $file }

This script is in biterscripting. Save this script as C:\Scripts\FillColumn.txt. Start biterscripting. Call the script with the command

script FillColumn.txt file("X.csv") column(2) value("Yes")

That should do it. As far biterscripting, download it free from any of the web sites. Make sure you follow installation instructions at .


Report •

June 3, 2009 at 10:55:10
Thanks Sen! Sorry for the delayed response I got buried in
adding PHP scripts to the data integration project I'm working

This will run from a server that I can't load biterscripting on, is
it possible to do the same thing using DOS cmds?


Report •

June 4, 2009 at 10:30:31
Hi Lou:

Hmm, in terms of DOS commands, I am tempted to say - yes, it can be done. But, I can't write a DOS script yet without doing more thinking. In general, the 'atomic' objects that DOS commands operate on, are entire files and not rows and columns. I am guessing that it is possible to operate at the levels of rows and columns using DOS commands, it may just not be very intuitive.

Do feel free to translate this biterscript's functionality to DOS commands. If you know php, it is my guess that it will be easier to translate it into PHP than DOS.


(When translating, change the 'var int file, column ; var str value' in the script to 'var int column ; var str file, value'.)

Report •

Related Solutions

June 4, 2009 at 11:17:30
Why can this not be done within the rdbms?

Either set the default field value for "DoNotMail" to "Yes" or a simple query like

update tablename set DoNotMail = "Yes" where DoNotMail IS NULL;

Report •

June 4, 2009 at 14:57:01
Hi Sen,

It's a big mess. I can't touch the rdbm but, I need to automate
the process (solved now by M2 in another question:

<a href="</a>" target="_blank">

and prepare .csv for import into
a mailing program, then sync back to rdbm with OptOuts.

But back to your point...DOS batch was not enough, now
thanks to M2, I am beginning to understand the power of
cmd.exe, which took the task over the top. (see

I've automated most of the functions now and have written
PHP scripts for other API functions, I'm sailing, time to go
grab a beer!

This site is tops!

Report •

Ask Question