hive export to pipe delimited file

How to change the below command so that i can export the output file as a pipe delimited file.

shellcommand='''hive -e 'set hive.cli.print.header=true; set hive.resultset.use.unique.column.names=false; use hivedb1; %s; ' | sed 's/[\t]/,/g' > %s '''%(selectqry,'path/outputfile.txt')

1 Answer

You can redirect the hive output with linux redirection. The standard output is resultset. You can concat the output columns with concat_ws function. Like:

CMD=`hive -e "set hive.cli.print.header=true; set hive.resultset.use.unique.column.names=false; use hivedb1; select concat_ws('|',col_1,col_2,col_3) from tbl" 1> output_file.txt 2> log.txt`
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like