文本排序:sort
      -n:数值排序
      -r: 降序
      -t: 字段分隔符
      -k: 以哪个字段为关键字进行排序
      -u: 排序后相同的行只显示一次
      -f: 排序时忽略字符大小写
##########################################################################
DESCRIPTION
 -n, --numeric-sort
              compare according to string numerical value
       -r, --reverse
              reverse the result of comparisons
       -t, --field-separator=SEP
              use SEP instead of non-blank to blank transition
       -k, --key=POS1[,POS2]
              start a key at POS1, end it at POS2 (origin 1)
       -u, --unique
              with -c, check for strict ordering; without -c, output only the first of an equal run
       -f, --ignore-case
              fold lower case to upper case characters
例子:/etc/passwd 的第三例数字从小到大排列
[root@zdx30 ~]# sort -t: -k3 -n /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/etc/news:
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nscd:x:28:28:NSCD Daemon:/:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin
smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
avahi:x:70:70:Avahi daemon:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
pcap:x:77:77::/var/arpwatch:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
 
##########################uniq#######################
uniq:
      -c: 显示文件中行重复的次数
      -d: 只显示重复的行(相邻的行)
      -D: 把所有重复的行都显示出来(相邻的行)
 
例子:
[root@data-1-3 scripts]# cat 1.txt
456
456
123
11
34
5678
456
[root@data-1-3 scripts]# uniq -c 1.txt
      2 456
      1 123
      1 11
      1 34
      1 5678
      1 456
[root@data-1-3 scripts]# uniq -c 1.txt
      2 456
      1 123
      1 11
      1 34
      1 5678
      1 456
[root@data-1-3 scripts]# uniq -d 1.txt
456
[root@data-1-3 scripts]# uniq -D 1.txt 
456
456
[root@data-1-3 scripts]# sort  1.txt |uniq -d
456
[root@data-1-3 scripts]# sort  1.txt |uniq -D
456
456
456
[root@data-1-3 scripts]# sort  1.txt |uniq -c
      1 11
      1 123
      1 34
      3 456
      1 5678
###########################WC使用##################
文本统计:wc (word count)
      -l:多少行
      -w:多少单词
      -c:多少字符
      -L:最长的一行包含了多少个字符
[root@data-1-3 scripts]# wc /etc/fstab
 15    78      779   /etc/fstab
 行数  单词数   字节
[root@data-1-3 scripts]# wc -l /etc/fstab
15 /etc/fstab
[root@data-1-3 scripts]# wc -w /etc/fstab 
78 /etc/fstab
[root@data-1-3 scripts]# wc -c /etc/fstab 
779 /etc/fstab
[root@data-1-3 scripts]# wc -m /etc/fstab 
779 /etc/fstab
 

shell之sort和uniq 及wc 的使用的更多相关文章

  1. sort,uniq,wc,tr

    sort (选项)(参数)      sort是用来排序数据的. 以下面这个文本为例 [root@bogon ~]# cat a 123 4567 88 abc aaa AAA jk 777 777 ...

  2. Linux Shell 文本处理工具集锦--Awk―sed―cut(row-based, column-based),find、grep、xargs、sort、uniq、tr、cut、paste、wc

    本文将介绍Linux下使用Shell处理文本时最常用的工具:find.grep.xargs.sort.uniq.tr.cut.paste.wc.sed.awk:提供的例子和参数都是最常用和最为实用的: ...

  3. Shell学习(七)——sort、uniq、cut、wc命令详解

    Shell学习(七)--sort.uniq.cut.wc命令详解 转自:[1]linux sort,uniq,cut,wc命令详解 https://www.cnblogs.com/ggjucheng/ ...

  4. linux sort,uniq,cut,wc.

    文章转自 http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858385.html sort sort 命令对 File 参数指定的文件中的行排 ...

  5. [转]linux sort,uniq,cut,wc命令详解

    sort sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sort 命令将这些文件连接起来,并当作一个文件进行排序. sort语法 ...

  6. linux sort,uniq,cut,wc命令详解

    linux sort,uniq,cut,wc命令详解 sort sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sort 命令将这些 ...

  7. linux sort,uniq,cut,wc,tr命令详解

    sort是在Linux里非常常用的一个命令,对指定文件进行排序.去除重复的行 sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sor ...

  8. Linux之 sort,uniq,cut,wc命令详解

    sort sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sort 命令将这些文件连接起来,并当作一个文件进行排序. sort语法 ...

  9. Ubuntu 14.10 下sort,uniq,cut,wc命令详解

    sort sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sort 命令将这些文件连接起来,并当作一个文件进行排序. sort语法 ...

随机推荐

  1. android状态栏总结

    针对状态栏的操作,只针对4.4kitKat(含)以上的机型,部分国产rom会失效,目前发现的有华为的EMUI Activity必须是noActionbar主题 本文基于StatusBarUtils略作 ...

  2. JMeter 压力測试使用函数和 CSV 文件參数化 json 数据

            在 http Load Testing 中.json 数据的提交是个让人头疼的问题.本文具体介绍怎样进行 JMeter 的 json 測试提交,以及怎样将其參数化.        St ...

  3. SolidEdge 工程图中如何标注尺寸公差

    1 先标注基准框,输入基准符号(A B C之类的)   2 点击特征控制,设置马上要标注的特征和公差(可以保存为模板)   3 直接点击要标注的元素即可   4 没有基准的形位公差标注也一样  

  4. java中自带时间类使用方法实例 Date,Timestamp,DateFormat

    我们将以Java自带的时间日期类和当中的处理函数进行分析. 一.与时间日期有关的类. java.util.Date. 实现类,其对象具有时间.日期组件. java.util.Calendar. 抽象类 ...

  5. odoo小数精确度

    python round() 函数     Python用于四舍五入的内建函数round() ,它的定义为 意思是, 将 小数部分保留到 ndigits 指定的 小数位,也就是 精度保持到 ndigi ...

  6. gulp(基础篇)

    今天在写项目的时候用到了gulp构建工具,虽然一年前就有用过,但是一直只存在于我的“有道云笔记”里,今天又一次用到,固然是巩固一下,这里来记录一下吧:这里我主要想要记录的就是初学者在第一次使用gulp ...

  7. OI知识体系

  8. Hadoop学习笔记(一)——Hadoop体系结构

    HDFS和MapReduce是Hadoop的两大核心. 整个Hadoop体系结构主要是通过HDFS来实现分布式存储的底层支持的,而且通过MapReduce来实现分布式并行任务处理的程序支持. 一.HD ...

  9. git操作-如何把你的本地仓库放到GitHub已有仓库

    本地: 首先在你的本地git init 初始化一个仓库,然后git add . 将所有的文件都打包到仓库中,git -commit -m "first_commit" 此时是没有什 ...

  10. poj3040(双向贪心)

    Allowance Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1540   Accepted: 637 Descript ...