Search code examples
regexmacosgrepzsh

How to capture app version to console via grep and regex?


My regex is weak. I am ashamed, but it's true.

I can log the entire line containing a Mac app's (Xcode's) version to the console via a command like this:

defaults read /Applications/Xcode.app/Contents/Info.plist | grep 'CFBundleShortVersionString = "'

That displays a line like this:

    CFBundleShortVersionString = "14.2";

How would I add a regex to the grep command to capture the "14.2" bit? I know I need to use something like `([0-9]+.[0.9]+) (capture 1 or more digits, a period, and one or more digits) but can't get it to work.


Solution

  • Just pipe that line into

    .... | grep -o -E '[0-9]+[.][0-9]+'