2

I try to grab just the version number of qrencode but it does not work. Any idea why?

$ qrencode --version | head -1 | awk '{print $3}'
qrencode version 3.4.4
Copyright (C) 2006-2012 Kentaro Fukuchi

I am quite confused because this sort of techniques use to work fine with most packages:

$ gzip --version | head -1 | awk '{print $2}'
1.6

Edit: thanks for the help. This is because for qrencode the output of --version is print to stderr instead of stdout. According so answer comments this is common to some extend. A bit weird to me, but fair enough.

Zorglub29
  • 6,979
  • 6
  • 20
  • 37

2 Answers2

2

Could you please try following.

qrencode --version 2>&1 | awk 'FNR==1{print $3;exit}'
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
1

You may redirect stderr to stdout:

qrencode --version 2>&1 | head -1 |  awk '{print $3}'
                   ^^^^

Output: 3.4.4

If you want to get rid of head -1 and get the same results with awk use

qrencode --version 2>&1 | awk 'NR==1{print $3}'

See cut or awk command to print first field of first row for details.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563