文本排序: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 View 测量流程(Measure)完全解析

    前言 上一篇文章,笔者主要讲述了DecorView以及ViewRootImpl相关的作用,这里回顾一下上一章所说的内容:DecorView是视图的顶级View,我们添加的布局文件是它的一个子布局,而V ...

  2. python 使用cx-freeze打包程序

    python环境 3.6.5      win7   linux环境同理 先尝试了PyInstaller   ,打包时一直提示 no module named gtk   而gtk 又依赖pygobj ...

  3. AngularJS的表单验证提交示例

    代码下载:https://files.cnblogs.com/files/xiandedanteng/angularjsFormSubmit.rar 前台代码: <%@ page content ...

  4. django 设置局域网内访问项目

    1. 关闭主机电脑上的防火墙(或者不用关闭,加一个端口号就行) 2.在你的settings.py文件中,找到ALLOWED_HOSTS=[ ],在中括号中加入你在局域网中的IP.例:我在局域网中的IP ...

  5. Git经常使用命令

    git --version 版本号号git help 帮助gitk 是个图形化的查看工具.gitk --all 所有分支历史-----------------------git pull 先拉git ...

  6. Solaris文件系统管理

    不同的操作系统使用不同类型的文件系统 1.文件(管理)系统:是用来对文件和目录进行管理.控制的数据结构的总称. Windows当中的文件系统: ntfs ,fat32 ,fat64 Solaris 当 ...

  7. 串匹配算法讲解 -----BF、KMP算法

      参考文章: http://www.matrix67.com/blog/archives/115     KMP算法详解 http://blog.csdn.net/yaochunnian/artic ...

  8. python(24)- 面向对象进阶

    面向对象基础知识: 1.面向对象是一种编程方式,此编程方式的实现是基于对类和对象的使用: 2.类是一个模板,模板中包装了多个‘函数’供使用(可以将多函数中公用的变量封装到对象中): 3.对象,根据模板 ...

  9. kubernetes对象之Job

    系列目录 job是什么 对于ReplicaSet.ReplicationController等类型的控制器而言,它希望pod保持预期数目.持久运行下去,除非用户明确删除,否则这些对象一直存在,它们针对 ...

  10. import caffe时出错:can not find module skimage.io

    import caffe时出错:can not find module skimage.io  //以下内容在ubuntu16.4上实际验证过.注意大小写的.----20170605 在命令行输入Py ...