sri
sri

Reputation: 161

Exporting the output of sqoop into a text file on local

I am trying to get the count of rows in a mysql table and trying to get the count of data into a text file onto local machine.

I am using the below command:

sqoop-eval --connect jdbc:mysql:url -username -password \
           --query"select count(*) from test" >> data.txt

I am getting the following output:

------------------------
| COUNT                |
------------------------
| 7548757              |
------------------------

I am looking for just the number in the output file as:

7548757

Nothing other than the count. How can i achieve it?

Upvotes: 3

Views: 3325

Answers (1)

agc
agc

Reputation: 8406

The output data is uncomplicated, so there's dozens of ways to do this, and here's a few:

  1. Using tr:

    sqoop-eval --connect jdbc:mysql:url -username -password \
               --query"select count(*) from test" | 
    { tr -cd '[:digit:]' ; echo ; } >> data.txt
    
  2. grep:

    sqoop-eval --connect jdbc:mysql:url -username -password \
               --query"select count(*) from test" | 
    grep -o '[[:digit:]]*' >> data.txt
    
  3. numgrep:

    sqoop-eval --connect jdbc:mysql:url -username -password \
               --query"select count(*) from test" | 
    numgrep -l /0../ >> data.txt
    

Output is the same for all three:

7548757

Upvotes: 4

Related Questions