Sponsored Content
Top Forums Shell Programming and Scripting How to export hive table data to a file on local UNIX? Post 302945395 by Chubler_XL on Thursday 28th of May 2015 11:08:07 PM
Old 05-29-2015
I expect you have typed the listed command from the hive Command line interface, your session log could have looked something like this (what you may have typed in blue):

Code:
user@your_host:~$ cd /usr/local/hive

user@your_host:/usr/local/hive$ hive

Logging initialized using configuration in jar:file:/usr/local/hive/lib/hive-common-0.11.0.jar!/hive-log4j.properties
Hive history file=/tmp/user/hive_job_log_user_1072@your_host_201505291127_11072.txt
hive> hive -e "select * from test" > /home/user/test.txt ;

NoViableAltException(26@[])
        at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:
        at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:19
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:434)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:352)
        at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:995)
        at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1038)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:931)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:921)
        at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:2
        at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:220)
        at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:422)
        at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:790
        at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:684)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:623)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
FAILED: ParseException line 1:0 cannot recognize input near 'hive' '-' 'e'


Instead you want to run hive from the shell command line, perhaps something like this (again your typed commands in blue):

Code:
user@your_host:~$ cd /usr/local/hive

user@your_host:/usr/local/hive$ hive -S -e "USE my_database; select * from test" > /home/user/test.txt

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to export data file from Unix

Hi, I am searching a way to export data file on Unix to SQL server on a daily bases. Any one has any ideas? Thanks in advance! (20 Replies)
Discussion started by: whatisthis
20 Replies

2. Shell Programming and Scripting

unix script to export data from csv file to oracle database

Hello people, Need favour. The problem I have is that, I need to develop a unix shell script that performs recurring exports of data from a csv file to an oracle database. Basically, the csv file contains just the first name and last name will be dumped to an Unix server. The data from these... (3 Replies)
Discussion started by: vinayagan
3 Replies

3. Shell Programming and Scripting

help for writing shell script to export table data

Hi All, I need to write a shell script(ksh) to take the tables backup in oracle(exporting tables data). The tables list is not static, and those are selecting through dynamic sql query. Can any body help how to write this shell script. Thanks, (3 Replies)
Discussion started by: sankarg
3 Replies

4. UNIX for Dummies Questions & Answers

UNIX - File/Table/Data manipulation

Hi, I have a table (e.g.): a 1 e 4 5 6 b 2 r 4 4 2 c 5 r 3 7 1 d 9 t 4 4 9 . . What I need to do is to set the values of some values in column 2 to negative values. For example, the values 2 and 9 should become -2 and -9 in the modified file. How should I go about... (2 Replies)
Discussion started by: pc2001
2 Replies

5. Shell Programming and Scripting

Export data from DB2 table to .txt file(space delimited)

Hi I need help on this. Its very urgent for me.. please try to help me out.. I have data in tables in DB2 database. I would like to export the data from DB2 tables into a text file, which has to be space delimited. so that I can carry out awk, grep operations on that file. I tried to export... (2 Replies)
Discussion started by: ss3944
2 Replies

6. Shell Programming and Scripting

How to export table data to xml file?

Hi , I would like to get some suggestion from the experts. My requirement is to export oracle table data as an xml file. Any unix/linux tools, scripts available? Regards, (2 Replies)
Discussion started by: LinuxLearner
2 Replies

7. Shell Programming and Scripting

Shell script to export data from Oracle table .

Hi, I want to write a shell script which will export data from oracle table . I don't want to save that data . I want the queries . Right now i am right clicking on the table and clicking on export as to my desktop . Please let me know if any one have any idea . (2 Replies)
Discussion started by: honey26
2 Replies

8. Linux

Parsing - export html table data as .csv file?

Hi all, Is there any out there have a brilliant idea on how to export html table data as .csv or write to txt file with separated comma and also get the filename of link from every table and put one line per rows each table. Please see the attached html and PNG of what it looks like. ... (7 Replies)
Discussion started by: lxdorney
7 Replies

9. Shell Programming and Scripting

Extract hive table structure

Hi, I need to extract only the create table structure with columns alone. for eg hive_table show create table hive_table: create table hive_table(id number,age number) OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat' LOCATION 'hdfs:/path/' I need only below ... (5 Replies)
Discussion started by: rohit_shinez
5 Replies

10. UNIX for Beginners Questions & Answers

Shell Script to read hive table and send email

HI Team, I am working on reading hive table and send email in email body using shell script, can you please help on fixing the errors: I have 6 columns in my hive table and trying to send the email in the mail body. below script: #!/bin/bash hive -e 'SELECT count(*) from db.table' >... (4 Replies)
Discussion started by: Mi4304
4 Replies
Win::Hivex::Regedit(3)					User Contributed Perl Documentation				    Win::Hivex::Regedit(3)

NAME
Win::Hivex::Regedit - Helper for reading and writing regedit format files SYNOPSIS
use Win::Hivex; use Win::Hivex::Regedit qw(reg_import reg_export); $h = Win::Hivex->open ('SOFTWARE', write => 1); open FILE, "updates.reg"; reg_import (*FILE, $h); $h->commit (undef); reg_export ($h, "\Microsoft\Windows NT\CurrentVersion", *OUTFILE, prefix => "HKEY_LOCAL_MACHINE\SOFTWARE"); DESCRIPTION
Win::Hivex::Regedit is a helper library for reading and writing the Windows regedit (or ".REG") file format. This is the textual format that is commonly used on Windows for distributing groups of Windows Registry changes, and this format is read and written by the proprietary "reg.exe" and "regedit.exe" programs supplied with Windows. It is not the same as the binary "hive" format which the hivex library itself can read and write. Note that the regedit format is not well-specified, and hence deviations can occur between what the Windows program can read/write and what we can read/write. (Please file bugs for any deviations found). Win::Hivex::Regedit is the low-level Perl library. There is also a command line tool for combining hive files and reg files (hivexregedit(1)). If you have a Windows virtual machine that you need to merge regedit-format changes into, use the high-level virt-win-reg(1) tool (part of libguestfs tools). FUNCTIONS reg_import reg_import ($fh, ($h|$map), [encoding => "UTF-16LE"]); This function imports the registry keys from file handle $fh either into the hive $h or via a map function. The hive handle $h must have been opened for writing, ie. using the "write => 1" flag to "Win::Hivex->open". In the binary hive file, the first part of the key name (eg. "HKEY_LOCAL_MACHINESOFTWARE") is not stored. You just have to know (somehow) that this maps to the "SOFTWARE" hive. Therefore if you are given a file containing a mixture of keys that have to be added to different hives, you have to have a way to map these to the hive handles. This is outside the scope of the hivex library, but if the second argument is a CODEREF (ie. reference to a function) then this $map function is called on each key name: map ($keyname) ==> ($h, $keyname) As shown, the function should return a pair, hive handle, and the true key name (with the prefix stripped off). For example: sub map { if ($_[0] =~ /^HKEY_LOCAL_MACHINE\SOFTWARE(.*)/i) { return ($software_h, $1); } else ... } "encoding" is the encoding used by default for strings. If not specified, this defaults to "UTF-16LE", however we highly advise you to specify it. See "ENCODING STRINGS" below. As with the regedit program, we merge the new registry keys with existing ones, and new node values with old ones. You can use the "-" (minus) character to delete individual keys and values. This is explained in detail in the Wikipedia page on the Windows Registry. Remember you need to call "$h->commit (undef)" on the hivex handle before any changes are written to the hive file. See "WRITING TO HIVE FILES" in hivex(3). reg_export reg_export ($h, $key, $fh, [prefix => $prefix], [unsafe_printable_strings => 1]); This function exports the registry keys starting at the root $key and recursively downwards into the file handle $fh. $key is a case-insensitive path of the node to start from, relative to the root of the hive. It is an error if this path does not exist. Path elements should be separated by backslash characters. $prefix is prefixed to each key name. The usual use for this is to make key names appear as they would on Windows. For example the key "Foo" in the SOFTWARE Registry, with $prefix "HKEY_LOCAL_MACHINESOFTWARE", would be written as: [HKEY_LOCAL_MACHINESOFTWAREFoo] "Key 1"=... "Key 2"=... If "unsafe_printable_strings" is not given or is false, then the output is written as pure 7 bit ASCII, with line endings which are the default for the local host. Strings are always encoded as hex bytes. This is safe because it preserves the original content and encoding of strings. See "ENCODING STRINGS" below. If "unsafe_printable_strings" is true, then strings are assumed to be UTF-16LE and are converted to UTF-8 for output. The final zero codepoint in the string is removed if there is one. This is unsafe because it does not preserve the fidelity of the strings in the Registry and because the content type of strings is not always UTF-16LE. However it is useful if you just want to display strings for quick hacking and debugging. You may need to convert the file's encoding using iconv(1) and line endings using unix2dos(1) if sending to a Windows user. Nodes and keys are sorted alphabetically in the output. This function does not print a header. The real regedit program will print a header like: Windows Registry Editor Version 5.00 followed by a blank line. (Other headers are possible, see the Wikipedia page on the Windows Registry). If you want a header, you need to write it out yourself. reg_export_node reg_export_node ($h, $node, $fh, ...); This is exactly the same as "reg_export" except that instead of specifying the path to a key as a string, you pass a hivex library $node handle. ENCODING STRINGS
The situation with encoding strings in the Registry on Windows is very confused. There are two main encodings that you would find in the binary (hive) file, 7 bit ASCII and UTF-16LE. (Other encodings are possible, it's also possible to have arbitrary binary data incorrectly marked with a string type). The hive file itself doesn't contain any indication of string encoding. Windows probably guesses the encoding. We think that regedit probably either guesses which encoding to use based on the file encoding, or else has different defaults for different versions of Windows. Neither choice is appropriate for a tool used in a real operating system. When using "reg_import", you should specify the default encoding for strings using the "encoding" parameter. If not specified, it defaults to UTF-16LE. The file itself that is imported should be in the local encoding for files (usually UTF-8 on modern Linux systems). This means if you receive a regedit file from a Windows system, you may sometimes have to reencode it: iconv -f utf-16le -t utf-8 < input.reg | dos2unix > output.reg When writing regedit files ("reg_export") we bypass this madness completely. All strings (even pure ASCII) are written as hex bytes so there is no doubt about how they should be encoded when they are read back in. COPYRIGHT
Copyright (C) 2010-2011 Red Hat Inc. LICENSE
Please see the file COPYING.LIB for the full license. SEE ALSO
Win::Hivex(3), hivexregedit(1), virt-win-reg(1), iconv(1), dos2unix(1), unix2dos(1), hivex(3), hivexsh(1), <http://libguestfs.org>, Sys::Guestfs(3). perl v5.16.3 2012-12-03 Win::Hivex::Regedit(3)
All times are GMT -4. The time now is 04:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy