1

I want to replace the ; in data to : in HIVE tried the following but not working

hive> select REGEXP_REPLACE('Mozilla/5.0 (Macintosh; Intel',';',':');

How to achieve this in HIVE. I am getting issues while transforming this.

adiga
  • 34,372
  • 9
  • 61
  • 83
BigD
  • 850
  • 2
  • 17
  • 40
  • Possible duplicate of [how to replace characters in hive?](https://stackoverflow.com/questions/18090481/how-to-replace-characters-in-hive) – suvartheec Dec 08 '17 at 10:01

3 Answers3

1

Just use replace():

select replace('Mozilla/5.0 (Macintosh; Intel', ';', ':')

replace() is described in the documentation.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

You need to escape the semicolon. Please see below

hive> select REGEXP_REPLACE("Mozilla/5.0 (Macintosh\; Intel","\;",":");
OK
Mozilla/5.0 (Macintosh: Intel
Time taken: 0.082 seconds, Fetched: 1 row(s)
Ramesh
  • 1,405
  • 10
  • 19
-1

U may try this

method 1: REGEXP_REPLACE('Mozilla/5.0 (Macintosh; Intel','\;',':');
method 2: REGEXP_REPLACE('Mozilla/5.0 (Macintosh; Intel','\\;',':');

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
fenny
  • 29
  • 4