linux shell中如何实现矩阵文件按照某一列的指定顺序排序

 

 

001、linux shell中如何实现矩阵文件按照某一列的指定顺序排序

[s20213040583@admin2 test]$ ls
a.txt  idx.txt
[s20213040583@admin2 test]$ cat a.txt       ## 测试数据
d       100     888
c       666     999
a       444     222
e       777     222
k       777     222
[s20213040583@admin2 test]$ cat idx.txt     ## 指定顺序
e
c
d
k
a
[s20213040583@admin2 test]$ awk '{if(NR == FNR){ay1[$1] = $0} else {if($1 in ay1) {print ay1[$1]}}}' a.txt idx.txt   ## 排序输出程序
e       777     222
c       666     999
d       100     888
k       777     222
a       444     222

。 

 

posted @ 2025-03-13 15:15  小鲨鱼2018  阅读(14)  评论(0)    收藏  举报