博客
关于我
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中使用IN()查询到底走不走索引?
查看>>
Mysql中使用存储过程插入decimal和时间数据递增的模拟数据
查看>>
MySql中关于geometry类型的数据_空的时候如何插入处理_需用null_空字符串插入会报错_Cannot get geometry object from dat---MySql工作笔记003
查看>>
mysql中出现Incorrect DECIMAL value: '0' for column '' at row -1错误解决方案
查看>>
mysql中出现Unit mysql.service could not be found 的解决方法
查看>>
mysql中出现update-alternatives: 错误: 候选项路径 /etc/mysql/mysql.cnf 不存在 dpkg: 处理软件包 mysql-server-8.0的解决方法(全)
查看>>
Mysql中各类锁的机制图文详细解析(全)
查看>>
MySQL中地理位置数据扩展geometry的使用心得
查看>>
Mysql中存储引擎简介、修改、查询、选择
查看>>
Mysql中存储过程、存储函数、自定义函数、变量、流程控制语句、光标/游标、定义条件和处理程序的使用示例
查看>>
mysql中实现rownum,对结果进行排序
查看>>
mysql中对于数据库的基本操作
查看>>
Mysql中常用函数的使用示例
查看>>
MySql中怎样使用case-when实现判断查询结果返回
查看>>
Mysql中怎样使用update更新某列的数据减去指定值
查看>>
Mysql中怎样设置指定ip远程访问连接
查看>>
mysql中数据表的基本操作很难嘛,由这个实验来带你从头走一遍
查看>>
Mysql中文乱码问题完美解决方案
查看>>
mysql中的 +号 和 CONCAT(str1,str2,...)
查看>>
Mysql中的 IFNULL 函数的详解
查看>>