GREL to pull out the first value in a multi-valued cell

24 views
Skip to first unread message

Steve

unread,
Nov 28, 2017, 8:09:24 PM11/28/17
to OpenRefine
I have a column with cells containing multiple values, separated by semicolons. Is there a way to pull out just the first value into a new column using a GREL script?

So if the cell was:
Doe, J; Smith, JD; Andersen SL

The new cell would be:
Doe, J

Owen Stephens

unread,
Nov 28, 2017, 8:16:33 PM11/28/17
to OpenRefine
Hi Steve,

You want to use the GREL function 'split'. Because you want this in a new column, you need to use the 'Column->Add column based on this column' menu option.
So do a Column->Add column based on this column and use the GREL:

value.split(";")[0]

The first part (value.split(";")) will split the value into an array (list) using semicolon as the character to split it up. The [0] directs OpenRefine to take the first item from the list created by the 'split' command. (and you can guess, using [1] instead would take the second value, [2] the third etc)

Owen

Steve

unread,
Nov 28, 2017, 8:27:20 PM11/28/17
to OpenRefine
Perfect, thanks very much Owen!

Thad Guidry

unread,
Nov 28, 2017, 11:11:58 PM11/28/17
to openr...@googlegroups.com
Owen's nice answer for an all to common ask on our mailing list. Making this #1 on our Recipes now as I just added it.  https://github.com/OpenRefine/OpenRefine/wiki/Recipes

Steven, did you read our use any of our documentation or getting help resources on our Wiki ? https://github.com/OpenRefine/OpenRefine/wiki
Just curious as we want to know how we can improve.


--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrefine+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steve

unread,
Nov 29, 2017, 3:28:05 PM11/29/17
to OpenRefine
Hi Thad,

I did go through the "GREL String Functions" page and tried to put together some code, but I did not spend the time going through the documentation or other help resources. Given how powerful OpenRefine is, I will definitely invest some time working through these. Thanks to all of you for your work on this project.

-Steve
Reply all
Reply to author
Forward
0 new messages