Apoorv Kumar
Apoorv Kumar

Reputation: 1

How to specify a different delimiter for different column in Hive?

One row of data looks like

"!Next?" (1994)                     Italy

I need to create 3 columns.

  1. Name of the Movie that is enclosed with ""
  2. Date of release that is enclosed with ()
  3. Country where the movie is produced

I need to specify different delimiter for each column.

One IMPORTANT thing - I am loading data from file /home/ap/Downloads/country.list

It would be great if could explain a little bit of query along.

Thanks in advance...

Upvotes: 0

Views: 230

Answers (1)

amow
amow

Reputation: 2223

use this cmd

cat YOUR_FILE_HERE|sed 's/"\(.*\)"\s*(\(.*\))\s*\([^\s].*\)/\1^A\2^A\3/g' > OUTPUT_FILE

then load this OUTPUT_FILE to your hive table.

REMEMBER:

I use \001 as delimiter here.If you change the table default fields terminater, use that to replace the ^A in my cmd.
And also the ^A is input by ctrl-v and then ctrl-a not the ^ and A.

Upvotes: 0

Related Questions