Command to find out the version number of a .pkg file

The best I could come up with was this:

pkgutil --expand package.pkg /tmp/pkg; cat /tmp/pkg/PackageInfo | grep ./Applications | grep -m 1 .app\" | awk '{ print $3, $2 }'; rm -rf /tmp/pkg

Not the most elegant solution, so I'm still searching for a way to do this without having to extract the .pkg first.


Variation of @d3Xt3r answer:

tar xOvf PackageName.pkg output.pkg/PackageInfo 2>/dev/null | grep '<pkg-info' \
    | sed "s#.* version=\"\([0-9\.]*\)\".*#\1#"

Advantage is that this is only pipe processing.

Note my package had different structure, there is an extra directory output.pkg which contains file PackageInfo