Sorting with conditions

瘦欲@ 提交于 2020-04-30 11:47:01

问题


Sort colunm 3, every two rows, and then sort columns 1 and 2

Input file

47329,39785,2,12,10,351912.50,2533105.56,170.93,1
47329,39785,2,12,28,351912.53,2533118.81,172.91,1
47329,39785,3,6,7,351912.82,2533105.07,170.89,1
47329,39785,3,6,20,351913.03,2533117.41,170.93,1
47329,39797,2,12,10,352063.14,2533117.84,170.66,1
47329,39797,2,12,28,352062.77,2533104.67,173.63,1
47329,39797,3,6,7,352064.11,2533119.32,170.64,1
47329,39797,3,6,20,352063.50,2533107.10,170.69,1

Desired Output

47329,39785,2,12,10,351912.50,2533105.56,170.93,1
47329,39785,3,6,7,351912.82,2533105.07,170.89,1
47329,39785,2,12,28,351912.53,2533118.81,172.91,1
47329,39785,3,6,20,351913.03,2533117.41,170.93,1
47329,39797,2,12,10,352063.14,2533117.84,170.66,1
47329,39797,3,6,7,352064.11,2533119.32,170.64,1
47329,39797,2,12,28,352062.77,2533104.67,173.63,1
47329,39797,3,6,20,352063.50,2533107.10,170.69,1

I tried

sort -t"," -k1 -k3 -k2 file
awk '{print int((NR-1)/4), $0}' file | sort -t"," -n -k1,1 -k3,3 | cut -f2- -d' '

Thanks in advance

来源:https://stackoverflow.com/questions/60183263/sorting-with-conditions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!