Calculating an integer with awk

I would like to extract a number from $0 and calculate if it can be devided by 25. Though the number can also be less then 25 or bigger than 100. How do i extract the number and how can the integer be calculated?

String:

"all_results">39</span>

I am looking for the number between

"all_results"> [number#] </span>

and then round it to an integer in this case 2

This is what i came up with so far:

awk -v ss="all_results" "{if ($0 ~ ss) print substr($0, match($0, ss)+13, 2)}" sid_search.html > number.txt

Your question may be too specific. "all_results">39</span> is not your input data, and the manner you use to strip it out may not be ideal or even reliable. Without seeing your actual input it's difficult to improve on it.

Once you get the number, you can easily enough test if things divide evenly with the modulus operator, %. It gives the integer remainder when divided by something. 101 % 25 would be 1.

@corona688, what would the ideal code be to strip out the number from this html code? Thanks for the hint on the modulus operator %.

If you are always using span tag then you can use the following code:-

echo "<span>56</span>" | awk -F'[<>]' ' { print $3%25 } '

Does this help?

Its probably not state of the art, at least I got the extraction of the number. Though could not resolve the integer calculation and thus print.

awk -v ss1="all_results" -v ss2="span" '{if ($0 ~ ss1) numb=index(substr($0,start=(index($0, ss1)+13), 10),ss2)-3} { numb=substr($0,start,numb); numb2=(numb / 25)}  {printf "%0f", numb2}'