Skip to main content
mark_hadoop
Gold ⭐️
Feb 6, 2019 6:29 PM UTC
Solved

Hive to extract multiple ip addresses from a string

Hi All,

I have a string

String:
some text with an ip 111.111.111.111 and a decimal 11.2323232 and some text here and then an int 1 and then some HTTP/1.1 with a 503 request and then another ip 222.222.222.222 and some imaginary 999.999.999.999

I want to output all the ip addresses in comma saperated. I tried the below

select regexp_replace(regexp_replace(String,'[^(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})]',' '),'\\s+',',');
+------------------------------------------------------------------------+--+
| _c0 |
+------------------------------------------------------------------------+--+
| ,111.111.111.111,11.2323232,1,1.1,503,222.222.222.222,999.999.999.999 |
+------------------------------------------------------------------------+--+

Expected output is : 111.111.111.111,222.222.222.222,999.999.999

Could you please help me

paulpaul1076
Gold ⭐️
Feb 8, 2019 12:17 AM UTC

Are you familiar with user defined functions?

2 replies

mark_hadoop
Gold ⭐️
Feb 8, 2019 12:04 AM UTC

@Shu can you please help me

Translate
paulpaul1076
Gold ⭐️
Feb 8, 2019 12:17 AM UTC

Are you familiar with user defined functions?

Translate