• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

parse qmake output from bash script

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]
0
NewtonianB
Asked:
NewtonianB
  • 2
2 Solutions
 
wesly_chenCommented:
$ qmake -v | head -1 |  awk -F'[:|(|)]' '{print $3}'
Qt 2.3.6

or
$ qmake -v | head -1 |  awk -F'[ |:|(|)]' '{print $7}'
2.3.6
0
 
NewtonianBAuthor Commented:
Hi wesly_chen I get the exact same output, am I missing something? seems my pipe is not working
0
 
wesly_chenCommented:
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 $)
0
 
simon3270Commented:
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

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now