parse qmake output from bash script

Posted on 2011-04-28
Last Modified: 2012-06-21
How can I extract the Qt version from a bash script using
qmake -v?

[newton@plex .home] qmake -v
Qmake version: 1.07a (Qt 2.3.6)
Qmake is free software from Trolltech AS.
[newton@plex .home]
Question by:NewtonianB
    LVL 38

    Accepted Solution

    $ qmake -v | head -1 |  awk -F'[:|(|)]' '{print $3}'
    Qt 2.3.6

    $ qmake -v | head -1 |  awk -F'[ |:|(|)]' '{print $7}'

    Author Comment

    Hi wesly_chen I get the exact same output, am I missing something? seems my pipe is not working
    LVL 38

    Expert Comment

    Please show me your command.
    The second one I post have "blank space" -F'[ |:|(|)]' , right after [

    Just copy and paste my command in to terminal. (no $)
    LVL 19

    Assisted Solution

    The output of "qmake -v" on my machine goes to standard error - you might need to redirect it to standard output such as:
    qmake -v 2>&1 | head -1 |  awk -F'[:|(|)]' '{print $3}'

    Open in new window

    You can simplify it a bit.  you don't need the pipe separators in awk's -F parameter  - this is a character class, not a set of regular expressions.  Also you don't need the "head" command - just exit the awk script after processing the first line:
    qmake -v 2>&1 | awk -F'[:()]' '{print $3;exit}'

    Open in new window


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
    I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension ( This reminded me of questions tha…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now