超碰97人人做人人爱2020,狠狠躁天天躁,久久精品人人槡人妻人人玩,超碰97人人做人人爱2020

  • <center id="frjpm"></center>

  • <big id="frjpm"><nobr id="frjpm"></nobr></big>
  • <object id="frjpm"></object>
  • 极速下载站 —— 提供优质软件下载服务,感受全新的极速下载体验!

    最近更新 | 软件专题 | 软件分类 | 软件排行

    您的位置:极速下载站资讯首页系统教程系统资讯 → 利用Linux命令行进行文本去重并按重复次数排序

    利用Linux命令行进行文本去重并按重复次数排序

    时间:2019-10-08 14:56:14  作者:无名  浏览量:58

    linux命令行提供了非常强大的文本处理功能,组合利用linux命令能实现好多强大的功能。本文这里举例说明如何利用Linux命令行进行文本去重并按重复次数排序。主要用到的命令有sort,uniq和cut。其中,sort主要功能是排序,uniq主要功能是实现相邻文本行的去重,cut可以从文本行中提取相应的文本列(简单地说,就是按列操作文本行)。
    利用Linux命令行进行文本去重并按重复次数排序
    利用Linux命令行进行文本去重并按重复次数排序图一
    用于演示的测试文件内容如下:
    [plain]
    Hello World.
    Apple and Nokia.
    Hello World.
    I wanna buy an Apple device.
    The Iphone of Apple company.
    Hello World.
    The Iphone of Apple company.
    My name is Friendfish.
    Hello World.
    Apple and Nokia.
    利用Linux命令行进行文本去重并按重复次数排序
    利用Linux命令行进行文本去重并按重复次数排序图二
    实现命令及过程如下:
    [plain]
    1、文本行去重
    (1)排序
    由于uniq命令只能对相邻行进行去重复操作,所以在进行去重前,先要对文本行进行排序,使重复行集中到一起。
    $ sort test.txt
    Apple and Nokia.
    Apple and Nokia.
    Hello World.
    Hello World.
    Hello World.
    Hello World.
    I wanna buy an Apple device.
    My name is Friendfish.
    The Iphone of Apple company.
    The Iphone of Apple company.
    (2)去掉相邻的重复行
    $ sort test.txt / uniq
    Apple and Nokia.
    Hello World.
    I wanna buy an Apple device.
    My name is Friendfish.
    The Iphone of Apple company.
    利用Linux命令行进行文本去重并按重复次数排序
    利用Linux命令行进行文本去重并按重复次数排序图三
    2、文本行去重并按重复次数排序
    (1)首先,对文本行进行去重并统计重复次数(uniq命令加-c选项可以实现对重复次数进行统计。)。
    $ sort test.txt / uniq -c
    2 Apple and Nokia.
    4 Hello World.
    1 I wanna buy an Apple device.
    1 My name is Friendfish.
    2 The Iphone of Apple company.
    (2)对文本行按重复次数进行排序。
    sort -n可以识别每行开头的数字,并按其大小对文本行进行排序。默认是按升序排列,如果想要按降序要加-r选项(sort -rn)。
    $ sort test.txt / uniq -c / sort -rn
    4 Hello World.
    2 The Iphone of Apple company.
    2 Apple and Nokia.
    1 My name is Friendfish.
    1 I wanna buy an Apple device.
    (3)每行前面的删除重复次数。
    cut命令可以按列操作文本行。可以看出前面的重复次数占8个字符,因此,可以用命令cut -c 9- 取出每行第9个及其以后的字符。
    $ sort test.txt / uniq -c / sort -rn / cut -c 9-
    Hello World.
    The Iphone of Apple company.

    12下一页>

    相关资讯

  • <center id="frjpm"></center>

  • <big id="frjpm"><nobr id="frjpm"></nobr></big>
  • <object id="frjpm"></object>
  • 超碰97人人做人人爱2020,狠狠躁天天躁,久久精品人人槡人妻人人玩,超碰97人人做人人爱2020

    品牌简介

    {转码主词}