Use sed to Replace NULL Columns

Viewed 1684

I'm using hive command to export data from Hive, it outputs a plain text file, fields terminated by \t, and lines terminated by \n.

Say there are some NULL columns, also some 'NULL' characters within a value, like the following:

NULL    NULL    NULL
ABCD    ABCDNULLABCD    ABCD-NULL-ABCD

I use the sed command to replace NULL with \N (for loading into MySQL):

hive -f query.sql | sed 's/\bNULL\b/NULL/g' >data.txt

The result is:

\N  \N  \N
ABCD    ABCDNULLABCD    ABCD-\N-ABCD

So the problem is, for \b modifier, '-' also matches, and the NULL between '-' is replaced.

Any way to solve this?

3 Answers
Related