Input. Let's say I have a file named f
with the following content:
+% H
% V
I can get the first column sorted in two ways:
First approach:
cat f | awk '{print $1}' | sort
Second approach:
cat f | sort -k 1 | awk '{print $1}'
Output & Question. It seems to me that it must be the same results, but it isn't: the output of the first command is:
%
+%
and of the second is:
+%
%
If I swap H
and V
in the second column of file output of the second command would change, but it shouldn't. Flag for stable sort doesn't change anything. All these were tested for bash versions:
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
and
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
.
So, my question is why do outputs differ?