博客
关于我
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/

你可能感兴趣的文章
memcached高速缓存学习笔记003---利用JAVA程序操作memcached crud操作
查看>>
Memcached:Node.js 高性能缓存解决方案
查看>>
memcache、redis原理对比
查看>>
memset初始化高维数组为-1/0
查看>>
Metasploit CGI网关接口渗透测试实战
查看>>
Metasploit Web服务器渗透测试实战
查看>>
MFC模态对话框和非模态对话框
查看>>
Moment.js常见用法总结
查看>>
MongoDB出现Error parsing command line: unrecognised option ‘--fork‘ 的解决方法
查看>>
mxGraph改变图形大小重置overlay位置
查看>>
MongoDB可视化客户端管理工具之NoSQLbooster4mongo
查看>>
Mongodb学习总结(1)——常用NoSql数据库比较
查看>>
MongoDB学习笔记(8)--索引及优化索引
查看>>
mongodb定时备份数据库
查看>>
mppt算法详解-ChatGPT4o作答
查看>>
mpvue的使用(一)必要的开发环境
查看>>
MQ 重复消费如何解决?
查看>>
mqtt broker服务端
查看>>
MQTT 保留消息
查看>>
MQTT 持久会话与 Clean Session 详解
查看>>