博客
关于我
sort、uniq、cut命令操作
阅读量:371 次
发布时间:2019-03-04

本文共 1380 字,大约阅读时间需要 4 分钟。

一、sort

(1)作用

  • sort命令用于对数据进行排序并输出结果
  • 它可以读取文件内容、标准输入或命令输出

格式:sort 选项 文件名

(2)常用选项

-r 按降序排列
-d 按升序排列
-n 按升序排列整数字段
-u 按升序排列并删除连续重复行

(3)案例

1、使用-r选项

[root@rzy ~]# cat aaa.txt 647853[root@rzy ~]# sort -r aaa.txt 876543

2、使用-d选项

[root@rzy ~]# cat aaa.txt 647853[root@rzy ~]# sort -d aaa.txt 345678

3、使用-n选项

[root@rzy ~]# cat aaa.txt 64478573[root@rzy ~]# sort -d aaa.txt 34457678[root@rzy ~]# sort -n aaa.txt 36784457

4、使用-u选项

[root@rzy ~]# cat aaa.txt 394445167778[root@rzy ~]# sort -u aaa.txt 13456789

二、Uniq

(1)作用

  • 用于删除连续重复行或统计行出现次数

格式:uniq 选项 文件名

(2)常用选项

-c 输出行出现次数
-u 删除连续重复行

(3)案例

1、使用选项-c

[root@rzy ~]# cat aaa.txt 394445167778[root@rzy ~]# uniq -c aaa.txt       1 3      1 9      3 4      1 5      1 1      1 6      3 7      1 8

2、使用选项-u

[root@rzy ~]# cat aaa.txt 394445167778[root@rzy ~]# uniq -u aaa.txt 395168

三、cut

(1)作用

  • 类似于简易版的awk,用于处理文本文件中的字段

格式:cut 选项 文件名

(2)常用选项

-d 指定分隔符,默认为空
-f 选择指定字段,-f1为第一个字段
-c 输出字节数

(3)案例

1、使用-d选项

[root@rzy ~]# cat aaa.txt a b c 目录[root@rzy ~]# cut -d' ' -f2 aaa.txt b

2、使用-f选项

[root@rzy ~]# cat aaa.txt a b c 目录[root@rzy ~]# cut -f3 aaa.txt a b c 目录[root@rzy ~]# cut -d' ' -f4 aaa.txt 目录

3、使用-c选项

[root@rzy ~]# cat aaa.txt a b c 目录[root@rzy ~]# cut -c1 aaa.txt a[root@rzy ~]# cut -c2 aaa.txt  [root@rzy ~]# cut -c3 aaa.txt b[root@rzy ~]# cut -c4 aaa.txt  [root@rzy ~]# cut -c5 aaa.txt c[root@rzy ~]# cut -c7 aaa.txt 目[root@rzy ~]# cut -c7,9  aaa.txt 目

转载地址:http://psbg.baihongyu.com/

你可能感兴趣的文章
Mysql 学习总结(89)—— Mysql 库表容量统计
查看>>
mysql 实现主从复制/主从同步
查看>>
mysql 审核_审核MySQL数据库上的登录
查看>>
mysql 导入 sql 文件时 ERROR 1046 (3D000) no database selected 错误的解决
查看>>
mysql 导入导出大文件
查看>>
MySQL 导出数据
查看>>
mysql 将null转代为0
查看>>
mysql 常用
查看>>
MySQL 常用列类型
查看>>
mysql 常用命令
查看>>
Mysql 常见ALTER TABLE操作
查看>>
MySQL 常见的 9 种优化方法
查看>>
MySQL 常见的开放性问题
查看>>
Mysql 常见错误
查看>>
mysql 常见问题
查看>>
MYSQL 幻读(Phantom Problem)不可重复读
查看>>
mysql 往字段后面加字符串
查看>>
mysql 快照读 幻读_innodb当前读 与 快照读 and rr级别是否真正避免了幻读
查看>>
MySQL 快速创建千万级测试数据
查看>>
mysql 快速自增假数据, 新增假数据,mysql自增假数据
查看>>