Shell学习四 -排序,唯一和重复

排序,唯一合重复

sort -n -r -M 

将两个文件中的内容排序

sort text1.txt text2.txt

将数字排序

sort -n numbers.txt

倒序排列

sort -r numbers.txt

按照月份排序

sort -M months.txt

找出已排序文件中不重复的行

sort text1.txt text2.txt |uniq

 

脚本练习

检查文件是否已经排过序

要检查文件是否排序过,可以采用以下方法:如果文件已经排序,sort会返回为0的退出码

($?),否则返回非0。

sh ifsorted.sh textq.txt

#!/bin/bash

sort -C $1 ;

if [ $? -eq 0 ] ; then

echo sorted;

else

echo Unsorted;

fi

sort 依据键或列进行排序

按照第一列逆排序 n 表示数字 。 r逆序 k排序列

sort -nrk 1 datatxt.txt

使用第一个字符作为建

sort -nk 1,1 datatxt.txt

 

uniq 从排过序的内容中取消重复的行

-c -u -d

统计文件中出现的次数

sort text1.txt text2.txt|uniq -c

 

找出文件中的重复行

sort text1.txt text2.txt|uniq -d

转载于:https://my.oschina.net/iioschina/blog/2218814

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值