While -k
option in sort
command helps to sort the data by given column but below example which is not perfectly tabular is still sorted by the column. How does it do it ? Which character it assumed in place of empty cells ?
test@ubuntu:~/Documents$ cat file1
a b c
d
e
test@ubuntu:~/Documents$ sort -k 2 file1
d
e
a b c
""
) sorts before any non-empty string in a lexicographical sort. There's no need to assume any character. This feels like a leading "trick" question -- sorry if you're genuinely confused and I'm just too suspicious ;-)cat -A file
, you will see that the entire line of d and e ared$
,e$
.