Tag Archives: linux

qmake: command not found…

QT - qmake I have started to learn QT and when I tried to compile my first practice program. I could not. qmake was missing. It was a silly oversight on my part or too late into the night. Nevertheless I am sure I am not the only one and someone might find this useful.

So you have installed QT and all the necessary libraries and every time you tried to run qmake, you  got  the “command not found” error message? Well…. it is not necessarily missing.

This exact problem happened to m and I couldn’t figure out for the life of me why it didn’t work. I was a little frustrated and decided to call it a  night when I did the simplest of things. I hit the tab key after typing qm and there it was:

qmake-qt5

You may have a different version, but it seems that the issue has been there for some time. Either use that command or create a symbolic link:

sudo ln -s `which qmake-qt5` /usr/bin/qmake

You may want to create the link somewhere in your home directory and add the location to your PATH. I have a local bin directory in ~/.local/bin/.

AWK: Sum of a Column

Imagine you have a file with multiple columns and you need to quickly get the total of a column in command line in UNIX. The easiest way is to use AWK in the command line.

Let’s take the following file:
datafile.txt

1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 10
3 4 5 6 7 8 9 11 12

To get the sum of column number 7 execute the following command:

awk '{sum+=$7} END {print sum}' datafile.txt

You will get the sum of 7, 8 and 9

24

Let’s now write a small script to calculate the sum of a column and also print a running total.

Input

2010 191 291 391 491 591 691 791 891 991
2011 144 286 391 491 591 691 791 891 991
2012 112 254 354 454 554 654 754 854 954
2013 191 291 391 491 591 691 791 891 991
2014 191 291 391 491 591 691 791 891 991
2015 178 291 391 491 591 691 791 891 991

Program

#!/bin/awk -f
# scriptname: calc_sum
# input: column number, data file
BEGIN {
    printf ("\tValue\tRunning total\n")
}
{
    sum += $colnum;
    printf ("%s:\t%.2f\t%.2f\n", $1, $colnum, sum)
}
END { 
    printf ("Total:%.2f\n", sum)
}

Command

$ calc_sum colnum=8 datafile.txt

Output

        Value   Running total
2010:   791.00  791.00
2011:   791.00  1582.00
2012:   754.00  2336.00
2013:   791.00  3127.00
2014:   791.00  3918.00
2015:   791.00  4709.00
Total:  4709.00

Of course you can run the above program from the command line, but it is neater and readable this way.