5

When I run this command I get a full table output....

mysql --user=root --password="mypassword" -e "SELECT btce_last_price FROM api.btc WHERE id=1"


+-----------------+
| btce_last_price |
+-----------------+
|             723 |
+-----------------+

I would like the output to be just "723".

3
  • 1
    Try adding --skip-column-names Commented Jan 1, 2014 at 21:22
  • This gives me. +-----+ | 723 | +-----+ Commented Jan 1, 2014 at 21:37
  • SOLVED adding "-s --skip-column-names" Commented Jan 1, 2014 at 22:43

3 Answers 3

6

Use the silent mode -s to produce less output. You can also add raw -r and --skip-column-names

Sign up to request clarification or add additional context in comments.

3 Comments

-s helps....I had to add grep to ignore tablename... mysql --user=root --password="mypassword" -e "SELECT btce_last_price FROM api.btc WHERE id=1" -s |grep -v btce_last_price.
or adding "head -1" to remove first line output.
SOLVED... "-s --skip-column-names"
1

The -N switch removes column names and you can use awk to strip the tabular formatting (whitespace, pipe & dash symbols):

SQL='SELECT btce_last_price FROM api.btc WHERE id=1'
mysql -u root -p "mypassword" -N -e "$SQL"|awk '{print $1}'

Comments

0

Try

mysql --user=root --password="mypassword" -e "SELECT btce_last_price FROM api.btc WHERE id=1" | tr -dc '[0-9]' 

That'll get you your bitcoin prices by pulling out only the numbers from that output.

If you aren't just looking for numbers, you can use

mysql --user=root --password="mypassword" --skip-column-names -e "SELECT btce_last_price FROM api.btc WHERE id=1"  | tr -d '[\+\-\| ]'

As long as there aren't and +, -, | or spaces in your value... otherwise you have to get trickier.

2 Comments

This works but not all values are numbers. How about if the value is "abc4329480_+908902"
This works for my requirements at this time. But I thought it should be easier to get any value. I tried to +1 but don't have enough rep yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.