I am trying to make a shell script, which will read number of lines (Like below) and only print "Queries per second avg: VALUE" string.
Threads: 1 Questions: 2459965658 Slow queries: 400 Opens: 103532 Flush tables: 165 Open tables: 64 Queries per second avg: 726.243
How can i realize this using shell script.?
sed
is the traditional tool for a job like this
sed -e 's/.* Queries/Queries/' your_file
Recent versions of bash, however, support regex natively.
while read -r line ; do
[[ $line =~ avg:\ .* ]] && echo Queries per second ${BASH_REMATCH[*]}
done < your_file
sed
sed -r 's/^.*(Queries.*)$/\1/'
bash
#!/bin/bash
while read -r line; do
echo "Queries${line##*Queries}"
done
... | grep -o 'Queries per second avg: [0-9.]\+'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.