Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么LinuxSort没有给我想要的结果?_Linux_Csv_Shell_Sorting - Fatal编程技术网

为什么LinuxSort没有给我想要的结果?

为什么LinuxSort没有给我想要的结果?,linux,csv,shell,sorting,Linux,Csv,Shell,Sorting,我有一个文件a.csv,其内容与下面类似 a,b,c a ,aa, a a b, c, f a , b, c a b a b a,a,a a,a,a a aa ,a , t 我正在尝试使用sort-k1-t,a.csv对其进行排序 但它给出了以下结果 a,a,a a ,aa, a a aa ,a , t a b a b a,a,a a , b, c a,b,c a b, c, f 这不是第一列上的实际排序。我做错了什么?您也必须将结束位置指定为1: sort -k1,1 -t, a.

我有一个文件a.csv,其内容与下面类似

a,b,c
a  ,aa,  a
a b, c, f
a , b, c
a b a b a,a,a
a,a,a
a aa ,a , t
我正在尝试使用
sort-k1-t,a.csv对其进行排序
但它给出了以下结果

a,a,a
a  ,aa,  a
a aa ,a , t
a b a b a,a,a
a , b, c
a,b,c
a b, c, f

这不是第一列上的实际排序。我做错了什么?

您也必须将结束位置指定为1:

sort -k1,1 -t, a.csv

您还必须将端点位置指定为1:

sort -k1,1 -t, a.csv

试试看:
sort-t,-k1,1 a.csv

该男子建议省略结束字段,它将对从字段
n
开始直到行尾的所有字符进行排序:

-k POS1[,POS2]'
     The recommended, POSIX, option for specifying a sort field.  The
     field consists of the part of the line between POS1 and POS2 (or
     the end of the line, if POS2 is omitted), _inclusive_.  Fields and
     character positions are numbered starting with 1.  So to sort on
     the second field, you'd use `-k 2,2' See below for more examples.

试试看:
sort-t,-k1,1 a.csv

该男子建议省略结束字段,它将对从字段
n
开始直到行尾的所有字符进行排序:

-k POS1[,POS2]'
     The recommended, POSIX, option for specifying a sort field.  The
     field consists of the part of the line between POS1 and POS2 (or
     the end of the line, if POS2 is omitted), _inclusive_.  Fields and
     character positions are numbered starting with 1.  So to sort on
     the second field, you'd use `-k 2,2' See below for more examples.
请尝试以下方法:

sort -k 1,1 -t , a.csv
sort将
-k1
读作“从第一个字段开始排序”--因此实际上违背了首先传递参数的观点

这将在中记录,并在示例部分中警告:

在第二个字段上进行数字排序 并通过排序解决关系 按字母顺序排列在第三和第四 第五栏的字符。使用“:”作为 字段分隔符:

$sort-t:-k2,2n-k5.3,5.4

请注意,如果您编写了
-k2
-k2,2
中,
排序将使用所有
以秒开头的字符
字段,并延伸到
行作为主数字键。对于
绝大多数申请,
处理跨越多个关键点的关键点
字段作为数字将不会执行您需要的操作
期待

请尝试以下方法:

sort -k 1,1 -t , a.csv
sort将
-k1
读作“从第一个字段开始排序”--因此实际上违背了首先传递参数的观点

这将在中记录,并在示例部分中警告:

在第二个字段上进行数字排序 并通过排序解决关系 按字母顺序排列在第三和第四 第五栏的字符。使用“:”作为 字段分隔符:

$sort-t:-k2,2n-k5.3,5.4

请注意,如果您编写了
-k2
-k2,2
中,
排序将使用所有
以秒开头的字符
字段,并延伸到
行作为主数字键。对于
绝大多数申请,
处理跨越多个关键点的关键点
字段作为数字将不会执行您需要的操作
期待


哦k1,1似乎表示要排序的列数。但是如果文字更糟糕,这会起作用吗。k1,1似乎表示要排序的列数。但是,如果单词更糟糕,这会起作用吗?示例中使用的是-n开关。示例中使用的是-n开关。