As devnull already commented, it will be tricky to automate parsing these strings. There are many, many browsers out there and barely any of them structure the User Agent string the same.
If you're interested in parsing text with Bash though I would recommend learning to use regular expressions and the linux command line tool sed
.
Using sed for example you could pull out any instance of Mac OS X followed by the version number like:
echo "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36" | sed 's/.*\(Mac\ OS\ X\ [0-9]\+_[0-9]\+_[0-9]\+\).*/\1/'
The sed command above matches the string Mac OS X #_#_#
. The numbers are represented with [0-9] and the plus sign following that indicates it is allowed to repeat. The command above returns the following:
Mac OS X 10_9_1
You could run something similar to parse out Chrome and it's version number like:
sed 's/.*\(Chrome\/[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/'
There's some more regex magic going on here such as matching groups (surrounding the portion we want to keep in parentheses and passing it over with \1) and escaping reserved characters such a space, plus, period, and forward slash.