tags:

views:

199

answers:

3

i need to make a graph with numeric values in a time period, the values represent online users in a web page.

the script will be exectued with cron every 30 mins and the needed html file will be downloaded with wget. but there are some yet unanswered questions & problems:

-i need to get just the numeric value from html code (but grep returns the whole line), how can I get only the numeric value? I can get the line with grep, it looks like this:

          Users online: 24 917     </div>

How can I get just the 24917?

-what would be easier? to generate .svg file with the graph, or save values in a .csv file (and generate graph with OOo or something similar). Maybe some other good ideas?

Thanks in advance,

-skazhy

A: 
grep filename|tr -d '</div>\n '|awk -F ':' '{print $2}'
Kimvais
That's nowhere near the correct way to use `tr`.
Dennis Williamson
A: 

Just one process (grep):

array=( $(grep whatever filename ) ) && echo  "${array[2]}${array[3]}"
fgm
+2  A: 

You can do the following to get your number:

Set the regular expression:

digits='[[:digit:]]+ *[[:digit:]]*'

followed by these two lines:

num=$(echo $line | grep -Eo "$digits")
num=${num// }

or these:

# Bash >= 3.2 (syntax may be different for 3.0/3.1)
[[ $line =~ $digits ]]
num=${BASH_REMATCH[@]// }

to extract the number from the variable $line containing the line in your question.

Gnuplot should be readily available. A few examples of its output can be found here.

These are from here.

example graph example graph

Dennis Williamson