0

I have a bash script as follows

#!/usr/bin/env bash
cd /Users/amar/Documents/ThesisCode/CEP_codes/mqtt-receiver

sqlite3 database <<EOF
SELECT sum(detection_time - generation_time)/count(*) from mobile_cep_data;
SELECT ((max(detection_time)- min(detection_time))*1000)/count(*) from mobile_cep_data;
EOF

it gives me result as

15
12

How can I get the result as

latency   = 15
thoughput = 12
1

2 Answers 2

4

@Cyrus's answer is fine and demonstrates a useful technique, and I've therefore upvoted it, but I'd like to point out that you can also do:

sqlite3 database <<EOF
SELECT 'latency   = ',
       sum(detection_time - generation_time)/count(*) from mobile_cep_data;
SELECT 'thoughput = ',
       ((max(detection_time)- min(detection_time))*1000)/count(*) from mobile_cep_data;
EOF
Sign up to request clarification or add additional context in comments.

2 Comments

Wow, thanks a lot for letting me know. This code workes too.
I think this approach is cleaner, portable and more appropriate
3

Replace

<<EOF

with

<<EOF | sed '1s/^/latency   = /;2s/^/thoughput = /'

1 Comment

Nice, using sed here is a smart idea. Thx a ton!

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.