Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PIG Script REPLACE with pipe symbol

I want to strip characters outside of the curly brackets in rows that look like the following.

35|{......}|

Stripping the '35|' from the front and the trailing '|' from the end.

{.....}

Initially working on the first 3 characters, I try the following but it removes everything.

 a = LOAD '/file' as (line1:chararray);

 b = FOREACH x generate REPLACE(line1, '35|','');

 dump b;

Any thoughts appreciated. Thanks.

like image 223
hivegotalovelybunchofcoconuts Avatar asked Aug 15 '26 06:08

hivegotalovelybunchofcoconuts


1 Answers

| and { and } are special characters in regular expressions and the second parameter for REPLACE is a regular expression. Try to escape the characters:

b = FOREACH x generate REPLACE(line1, '35\\|','');
like image 106
Frederic Avatar answered Aug 17 '26 12:08

Frederic