I have a file with some lines of data that I want to extract. I'm thinking awk
is a good fit for this. In pseudocode I'm imagining doing something like:
- Find match for line I want to process with
awk
- In the second part, inside the
{}
find a regex match for my data, maybe withgrep -o
? - Print the match, maybe at the end inside the
{}
or inside andEND
I'm not sure how to go about doing this, I know I'm not using cut
properly but I just showed it to give some idea of intent. Would love some help. Essentially I want to get my hands on the $0
and start extracting various regex matches so I can piece them together into my own CSV format.
This is what I've tried:
➜ tmp cat data.txt
Concurrency Level: 1
Time taken for tests: 0.004 seconds
Complete requests: 1
Failed requests: 0
Total transferred: 838 bytes
HTML transferred: 632 bytes
Requests per second: 257.40 [#/sec] (mean)
Time per request: 3.885 [ms] (mean)
Time per request: 3.885 [ms] (mean, across all concurrent requests)
Transfer rate: 210.65 [Kbytes/sec] received
➜ tmp cat data.txt | awk '/Complete requests:/ {print;}'
Complete requests: 1
➜ tmp cat data.txt | awk '/Complete requests:/ {print $0;}'
Complete requests: 1
➜ tmp cat data.txt | awk '/Complete requests:/ {print;}'|cut -d: -f2
1
I'm going for something like
Time taken for tests, 0.0004, s
Requests per second (mean), 257.40, #/sec
.
.
.
Transfer rate received, 210.65, Kbytes/sec
Because the data isn't very uniform that why I'm going to want to write a separate "post-regex-match" processing of $0
for each match /Concurrency Level:/
, Time taken for tests:
, etc