31

Is there any way I can output the results from a scan in the hbase shell to a file? I'm assuming this is easy but I haven't been able to find anything in the documentation.

Dave Novelli
  • 2,086
  • 4
  • 32
  • 42

4 Answers4

57

I know that this post is quite old but i was searching something about HBase myself and came across with it.

Well i don't know if this is the best way to do it, but you can definitely use the scripting option HBase gives you. Just open a shell (preferably go to the directory bin of HBase) and run

echo "scan 'foo'" | ./hbase shell > myText

where foo is the name of the table you want to scan. If you then open myText you will see the results in there. Hope i helped!

Alex Karnezis
  • 888
  • 9
  • 14
  • Worked like a charm :) – La-comadreja May 08 '14 at 16:33
  • 2
    The problem with this solution is that hbase is fairly chatty, so you don't just get the command output, you also get a bunch of hbase conversation. If you want to get data and parse it, it's pretty icky. – Ken Williams Aug 25 '14 at 15:12
  • @KenWilliams Also it is little slow. Is there any way faster way you know. Actually I have to execute a command in loop for 24 times and it is taking a lot of time and I don't want to write a java code to do that. – Pranjal Sahu May 04 '15 at 07:09
  • @sahu not that I know of - the best option might be to write the results to HDFS first, then export from HDFS to the local filesystem. – Ken Williams May 04 '15 at 15:55
  • It works! Need to run in directly in shell. Not in HBase shell prompt – Sakthivel May 01 '17 at 23:32
10

Another option using an EOF here doc, potentially more customizable:

hbase shell <<EOF >myText
scan 'foo'
EOF
rupert160
  • 1,441
  • 1
  • 17
  • 19
5

You can also use here strings too (if your shell supports them):

$ hbase shell <<< "scan 'sometable'" > myoutput.txt

Above I'm doing this in Bash on a Linux system, for example.

slm
  • 15,396
  • 12
  • 109
  • 124
2

ex : file.sh contains scan 'tablename';

Execute bellow command to capture result to log file....

hbase shell < file.sh(which contains hbase commands) > output.lo
Himanshu Bansal
  • 2,003
  • 1
  • 23
  • 46