Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.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
Bash 使用Shell命令对文件排序_Bash_Shell_Sorting_Sed_Awk - Fatal编程技术网

Bash 使用Shell命令对文件排序

Bash 使用Shell命令对文件排序,bash,shell,sorting,sed,awk,Bash,Shell,Sorting,Sed,Awk,我有这样的数据 $ cat file (71149, 3079, 68070, 0.0433) Alex (51135, 2881, 48254, 0.0563) Brandon (27231, 7105, 20126, 0.2609) Chad (8365, 3634, 4731, 0.4344) Daniel (7490, 7346, 144, 0.9808) Eliz (6841, 3917, 2924, 0.5726) Frank (6740, 7393, -653, 1.0969) G

我有这样的数据

$ cat file
(71149, 3079, 68070, 0.0433) Alex
(51135, 2881, 48254, 0.0563) Brandon
(27231, 7105, 20126, 0.2609) Chad
(8365, 3634, 4731, 0.4344) Daniel
(7490, 7346, 144, 0.9808) Eliz
(6841, 3917, 2924, 0.5726) Frank
(6740, 7393, -653, 1.0969) Gates
(5084, 500, 4584, 0.0983) Harry
(5044, 3913, 1131, 0.7758) Ian
(4760, 699, 4061, 0.1468) Jack
....
我想按括号中的最后一个元素对内容进行排序,如何在命令行中进行排序

$ cat file | ... magic ... 
(6740, 7393, -653, 1.0969) Gates
(7490, 7346, 144, 0.9808) Eliz
(5044, 3913, 1131, 0.7758) Ian
(6841, 3917, 2924, 0.5726) Frank
(8365, 3634, 4731, 0.4344) Daniel
(27231, 7105, 20126, 0.2609) Chad
(4760, 699, 4061, 0.1468) Jack
(5084, 500, 4584, 0.0983) Harry
(51135, 2881, 48254, 0.0563) Brandon
(71149, 3079, 68070, 0.0433) Alex
....
我成功地对数字进行了排序,但我不知道如何用awk打印整行

$cat file | sed 's/)//g' | awk 'BEGIN{FS=" "}{print $4}' | sort -r
5.1246
4.3936
2.7811
2.5
1.9
....

默认的字段分隔符应该是空白,对吗?第四个元素实际上是“1.0969”,包括括号。。。即使字段中有奇怪的字符,你仍然可以排序?@B.Mr.W。只要该列中始终有4位小数,它就可以正常工作。@B.Mr.W。如果您对查看结果更感兴趣,并且特定的输出格式不重要,那么更一致的排序应该是
cat文件| tr-d'(),| sort-k4nr
kent$  sort  -k4nr file
(6740, 7393, -653, 1.0969) Gates
(7490, 7346, 144, 0.9808) Eliz
(5044, 3913, 1131, 0.7758) Ian
(6841, 3917, 2924, 0.5726) Frank
(8365, 3634, 4731, 0.4344) Daniel
(27231, 7105, 20126, 0.2609) Chad
(4760, 699, 4061, 0.1468) Jack
(5084, 500, 4584, 0.0983) Harry
(51135, 2881, 48254, 0.0563) Brandon
(71149, 3079, 68070, 0.0433) Alex