Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.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
Linux awk排序降序不起作用_Linux_Sorting_Awk - Fatal编程技术网

Linux awk排序降序不起作用

Linux awk排序降序不起作用,linux,sorting,awk,Linux,Sorting,Awk,我有两个文件需要整理 我使用的命令是: cat first-in.txt | awk '{print $2}' | cut -d '/' -f 3 | cut -d '^' -f 1 | sort -b -t . -k 1,1nr -k 2,2nr -k 3,3r -k 4,4r -k 5,5r | uniq > first-out.txt cat second-in.txt | awk '{print $2}' | cut -d '/' -f 3 | cut -d '^' -f 1

我有两个文件需要整理

我使用的命令是:

cat first-in.txt | awk '{print $2}' | cut -d '/' -f 3 | cut -d '^' -f 1 | sort -b -t . -k 1,1nr -k 2,2nr -k 3,3r -k 4,4r -k 5,5r | uniq > first-out.txt


cat second-in.txt | awk '{print $2}' | cut -d '/' -f 3 | cut -d '^' -f 1 | sort -b -t . -k 1,1nr -k 2,2nr -k 3,3r -k 4,4r -k 5,5r | uniq > second-out.txt
问题是: 我需要按降序正确排序,因为现在只有文件2排序正确,但文件1排序不正确

我想知道我犯了什么错误

文件


提前谢谢。

我想你的意思是这是错误的:

4.2.4
4.2.3
4.2.20
4.2.2
您希望
4.2.20
高于所有这些,对吗

您可以通过更改
排序的
-k
参数将所有字段视为数字来解决此问题:

.... -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr -k 5,5nr ....
在GNU/Linux系统上,您可以使用带-V选项的排序:


请注意,sed-r和sort-V都不是标准的。

列出第一个和第二个文件,以及您希望输出的方式。这个
cat first-in.txt | awk'{print$2}| cut-d'/'-f3 | cut-d'^'-f1
可以更改为
awk'{split($2,a,“/”);split(a[3],b,“^”);print b[1]}first-in.txt | sort…
@Jotne,out必须类似。
sed -r 's|.*/([^/^]*).*$|\1|' infile | sort -Vr