linux 中实现数据的每一行进行排序

 

001、

复制代码
(base) [b20223040323@admin1 test2]$ ls
a.txt
(base) [b20223040323@admin1 test2]$ cat a.txt    ## 测试数目
6 8 9 3 7
5 2 5 6 8
8 2 4 2 7
(base) [b20223040323@admin1 test2]$ for i in {1..3}; do sed -n "$i"p a.txt | sed 's/ /\n/g' | sort | paste -s -d " " >> b.txt; done
(base) [b20223040323@admin1 test2]$ ls                      ## 每一行正向排序
a.txt  b.txt
(base) [b20223040323@admin1 test2]$ cat b.txt       ## 排序结果
3 6 7 8 9
2 5 5 6 8
2 2 4 7 8
(base) [b20223040323@admin1 test2]$ for i in {1..3}; do sed -n "$i"p a.txt | sed 's/ /\n/g' | sort -r | paste -s -d " " >> c.txt; done
(base) [b20223040323@admin1 test2]$ ls
a.txt  b.txt  c.txt
(base) [b20223040323@admin1 test2]$ cat c.txt      ## 每一行实现逆向排序
9 8 7 6 3
8 6 5 5 2
8 7 4 2 2
复制代码

 

 

posted @   小鲨鱼2018  阅读(49)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2021-04-21 linux shell脚本中流程控制语句 if 、for、while、case
2021-04-21 linux系统中条件测试语句
2021-04-21 linux系统 shell脚本 接收用户的参数
2021-04-21 linux 系统中read命令
2021-04-21 linux系统中 while read逐行读取数据
2021-04-21 linux系统中统计文本中单词出现的次数
点击右上角即可分享
微信分享提示