1

I am trying to output all tables in a database to an csv or text file.

I can output all the databases by using "show databases" and I can show all the tables in the databases by using "dal_std" but how to loop through all the tables and export it to a csv or text file is what I am trying to do.

I am new to shell scripts but here is what i have so far:

hive -e "show databases" > d.txt

for line in d.txt:
hive -e "show tables in database > output.txt

Any ideas or simply ways to do this?

James Davinport
  • 303
  • 7
  • 19

1 Answers1

2

You almost reached to an end. just adding up few more details to finish it up!

#!/bin/bash
echo "Executing the shell script"
hive -e "show databases" > databases.txt
for i in `cat databases.txt`
do
    printf "Given database name has below set of tables:"$i >> tableslist.txt
    printf '\n' >> tableslist.txt
    hive -e "show tables in $i" >> tableslist.txt

done
echo "shell scripts ends"
vikrant rana
  • 4,509
  • 6
  • 32
  • 72