用管道符号替换 PIG 脚本 [英] PIG Script REPLACE with pipe symbol

查看:26
本文介绍了用管道符号替换 PIG 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在如下所示的行中去除大括号外的字符.

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

35|{......}|

去掉'35|'从前面和尾随 '|'从最后.

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

{.....}

最初处理前 3 个字符,我尝试了以下操作,但它删除了所有内容.

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.

推荐答案

|{} 是正则表达式中的特殊字符和REPLACE 的第二个参数是一个正则表达式.尝试转义字符:

| 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\\|','');

这篇关于用管道符号替换 PIG 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆