Is there an easy way to extract variables from a text file?
E.g. given the output from ab
:
This is ApacheBench, Version 2.3 <$Revision: 1638069 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking bar (be patient)
Finished 1206 requests
Server Software: Jetty(9.0.z-SNAPSHOT)
Server Hostname: bar
Server Port: 5500
Document Path: /foo/1
Document Length: 148 bytes
Concurrency Level: 15
Time taken for tests: 30.041 seconds
Complete requests: 1206
Failed requests: 0
Total transferred: 359686 bytes
HTML transferred: 178636 bytes
Requests per second: 40.15 [#/sec] (mean)
Time per request: 373.643 [ms] (mean)
Time per request: 24.910 [ms] (mean, across all concurrent requests)
Transfer rate: 11.69 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 47 108 36.0 98 328
Processing: 73 264 782.5 150 7951
Waiting: 73 255 721.5 148 7886
Total: 129 371 783.5 259 8039
Percentage of the requests served within a certain time (ms)
50% 259
66% 293
75% 324
80% 340
90% 413
95% 525
98% 683
99% 6421
100% 8039 (longest request)
I'd like to extract values (matching name: value
, see example below) and assign them to variables in one step. (I know that ab
can export some data to csv but the rest is only available as formatted text.)
The best I've found so far is:
path=$(cat text|grep 'Document Path:'|awk -F: '{ split($2, z, " "); print z[1]}')
total=$(cat text|grep 'Total transferred:'|awk -F: '{ split($2, z, " "); print z[1]}')
#[...]
But this seems to be a bit repetitive and awkward - is there an easier way or a tool that's better suited for this job?
ApacheBench
a value? Is50%
? Or should it be50
? Show us a specific example and the output you would like to see. As it stands, this is just too broad. And yes, of course there are easy ways to do this but it all depends on what you want to extract.foo:
) to be variable names. Is that correct?