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

你可能感兴趣的文章
mysql5.7安装
查看>>
mysql5.7性能调优my.ini
查看>>
MySQL5.7新增Performance Schema表
查看>>
Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
查看>>
Webpack 之 basic chunk graph
查看>>
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>