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?
The output data is uncomplicated, so there's dozens of ways to do this, and here's a few:
Using tr
:
sqoop-eval --connect jdbc:mysql:url -username -password \
--query"select count(*) from test" |
{ tr -cd '[:digit:]' ; echo ; } >> data.txt
grep
:
sqoop-eval --connect jdbc:mysql:url -username -password \
--query"select count(*) from test" |
grep -o '[[:digit:]]*' >> data.txt
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