I am learning awk from this tutorial. It's quite basic. I have a list of processes in a file which I got by doing ps aux > processes Now according to the tutorial, doing awk '$2 ~ 14022, $2 ~ 14040' should give a range of processes with PID ranging from 14022 to 14040. I tried the same with PID range 1746 - 1760. But it outputs the processes which have PID above 1760. Output$ awk '$2 ~ 1746, $2 ~ 1760 {print $1, $2, $11}' processes root 1746 sudoroot 1750 wvdialroot 1751 /usr/sbin/pppddharmit 1772 /opt/google/chrome/chromedharmit 1788 /opt/google/chrome/chromedharmit 1790 /opt/google/chrome/chromeroot 1791 /sbin/udevddharmit 1827 /opt/google/chrome/chromedharmit 1830 /opt/google/chrome/chromedharmit 1846 /opt/google/chrome/chromedharmit 1850 gnome-terminaldharmit 1856 gnome-pty-helperdharmit 1857 bashroot 1902 [kworker/0:4]dharmit 1940 /opt/google/chrome/chromeroot 1952 [kworker/1:0]root 2104 /usr/sbin/anacronroot 2181 /usr/libexec/packagekitddharmit 2183 psWhy does it happen so? What am I missing here? 
Awk : Range of PIDs
awk
You are specifying a range match where the end of the range does not match any of the input lines - i.e. there is no process with pid 1760.awk is not being smart here and knowing that the field is a numeric field and comparing the PIDs against a numeric range, as you seem to be expecting. Instead it is just simply matching a string for the start and end of the range, and with no match on the end of the range, the range effectively extends to end the end of the file.In your example, if you end the range at 1751 you will find you get what you want.Alternatively, compare the field numerically:awk '$2 >= 14022 && $2 <= 14040 { print }'That will work even if your input is not sorted.