Copy from one column to another

61 views
Skip to first unread message

jposb...@gmail.com

unread,
Feb 4, 2016, 7:02:29 AM2/4/16
to csvfix
Hi,

Is it possible to copy the contents of one field to another if the target column is empty using CSVFix? For example I have data in column 3 and I want to copy it to column 4 but only if it is empty.

Hopefully this makes sense but I'm unsure if this is possible so any help would be greatly appreciated.

Thanks and Best Regards

John

Neil Butterworth

unread,
Feb 4, 2016, 7:09:47 AM2/4/16
to csvfix, jposb...@gmail.com
Use the eval command:

        csvfix eval -r '4,if($4=="",$3,$4)' a.csv



jposb...@gmail.com

unread,
Feb 4, 2016, 10:02:42 AM2/4/16
to csvfix, jposb...@gmail.com
Hi Neil,

Thanks for the quick reply. I've tried running the command below against a simple CSV file (See below), but I'm getting the following error

ERROR: Invalid field (need integer):  '4

The CSV file I'm using as a test is

APPLES,PEARS,ORANGES,ORANGES,BANANAS
APPLES,PEARS,ORANGES,,BANANAS

I'm aiming to get the blank in the second row, column 4  populated with the contents of column 3 so that the result matches the first row.

Thanks again and best regards

John

Neil Butterworth

unread,
Feb 4, 2016, 10:05:31 AM2/4/16
to csvfix, jposb...@gmail.com
If you are using the Windows cmd.exe shell, you need to change the quotes:


      csvfix eval -r "4,if($4=='',$3,$4)" a.csv

Reply all
Reply to author
Forward
0 new messages