![]() ![]() In the C locale, ␠␠c sorts before ␠c as there is only one pass there where characters (then single bytes) sort based on their code point value (where space has a lower code point than c). Once we ignore the blanks, the sort key for the first 3 lines is the same ( c), so they are sorted by the last resort comparison. However, this method of sorting mixes the column headers in with the rest of the lines of output. In the first case, because ␠c␠c sorts before ␠c␠d, in the second case because the sort key is the same ( ␠c), the last resort comparison that compares the lines in full puts a b c d before a c c c. Without the headers, the cutting and sorting is easily accomplished via the -k option to sort along with cut or awk to view a subset of the columns. See how the order of a b c d and a c c c are reversed. Note how the one with ␠␠c (2 leading spaces) is retained. $ sort -u -k 3,3 aĪbove only one is retained for those where the 3rd column is ␠c. ␠ca␠d sorts before ␠c␠c because spaces are ignored in the first pass in my locale, cad sorts before cc. Line 2 and 3 have the same third column, but here the sort key is from the third column to the end of line, so -u retains both. If the columns are separated by something else, you need the -t option to specify the separator. u is to retain only one of the lines if there are several that sort identically (that is where the sort key sorts the same (that's not necessarily the same as being equal)).Ĭat is the command to con catenate. In the C locale, because the space and tab characters ranks before all the printable characters, that will generally give you the same result as -k 3,3 (except for lines that have an identical third field), k 3 is to sort on the portion of the lines starting with the 3 rd column (including the leading blanks). Note that it's completely independent from the shell (all the shells would parse that command line the same, shells generally don't have the sort command built in). Note that the leading blanks are included in the column (the default separator is the transition from a non-blank to a blank), that can make a difference in locales where spaces are not ignored for the purpose of comparison, use the -b option to ignore the leading blanks. Would display the file sorted by the 3 rd column assuming the columns are separated by sequences of blanks (ASCII SPC and TAB characters in the POSIX/C locale), according to the sort order defined by the current locale. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |