Quick Tip: CSVFIX Duplicate Column

One tool I use to do bulk data loads in to Salesforce.com does not allow mapping one source to multiple destination fields. You can of course use workflows or code to backfill the data once it gets in but a cheaper/easier alternative if it is just one field is the following:

// Works on Windows
csvfix eval -e "if($1!='',$1,$1)" etl_temp.csv > etl_temp2.csv

// Works on Mac
csvfix eval -e 'if($1!="",$1,$1)' etl_temp.csv > etl_temp2.csv

It is a bit of a hack but basically as long as there is a value in the column it copies it to the last column. $1 is the field position of that row, != is the not equals, and two single quotes for ‘Empty String’. The if statement uses double quotes for windows, use single quotes for non-windows.

Updated this Oct 6th 2022 with better formatting of the code as copy/paste was pulling formatted double quotes. Also added the mac version where you have to switch the single and double quotes around in order to work on a mac/linux.

Leave a Reply

Your email address will not be published. Required fields are marked *