博客
关于我
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-存储引擎
查看>>
mysql-开启慢查询&所有操作记录日志
查看>>
MySQL-数据目录
查看>>
MySQL-数据页的结构
查看>>
MySQL-架构篇
查看>>
MySQL-索引的分类(聚簇索引、二级索引、联合索引)
查看>>
Mysql-触发器及创建触发器失败原因
查看>>
MySQL-连接
查看>>
mysql-递归查询(二)
查看>>
MySQL5.1安装
查看>>
mysql5.5和5.6版本间的坑
查看>>
mysql5.5最简安装教程
查看>>
mysql5.6 TIME,DATETIME,TIMESTAMP
查看>>
mysql5.6.21重置数据库的root密码
查看>>
Mysql5.6主从复制-基于binlog
查看>>
MySQL5.6忘记root密码(win平台)
查看>>
MySQL5.6的Linux安装shell脚本之二进制安装(一)
查看>>
MySQL5.6的zip包安装教程
查看>>
mysql5.7 for windows_MySQL 5.7 for Windows 解压缩版配置安装
查看>>
Webpack 基本环境搭建
查看>>