zoukankan      html  css  js  c++  java
  • Linux基础--分类与合并命令

    1、sort
    sort命令将许多不同的域按不同的顺序分类,sort命令的一般格式为:
    sort -cmu -o output_file [other options] +pos1 +pos2 input_files   
    参数:
    -c        测试文件是否已经分类。
    -m       合并两个分类文件。
    -u        删除所有复制行。
    -o        存储sort结果的输出文件名。
    other options:
    -b         使用域进行分类时,忽略第一个空格。
    -n         指定分类是域上的数字分类。
    -t         域分隔符;用非空格或 tab键分隔域。
    -r         对分类次序或比较求逆。
    +n        n 为域号。使用此域号开始分类。
    n          n 为域号。在分类比较时忽略此域,一般与 +n一起使用。
    post1    传递到 m,n。m为域号, n为开始分类字符数,例如 4,6意即以第 5域分类,从第 7个字符开始。

    sort启动方式:
            缺省情况下,sort认为一个空格或一系列空格为分隔符。要加入其他方式分隔,使用 -t选项。sort执行时,先查看是否为域分隔设置了-t选项,如果设了,则使用它来将记录分隔成域0、域1等等;如果未设置,用空格代替。缺省时sort将整个行排序,指定域号的情况例外。sort的一个重要事实是它参照第一个域作为域0,域1是第二个域,等等


    命令行实例:   
    [root@redhat script]#cat video.txt 
    Boy in Company C:HK:192:1292
    Alien:HK:119:1982
    The Hill:KL:63:2972
    Aliens:HK:534:4892
    Star Wars:HK:301:4102
    A Few Good Men:KL:445:5851
    Toy Story:HK:239:3972
    [root@redhat script]#
    [root@redhat script]#sort -c video.txt 
    sort: video.txt:2: disorder: Alien:HK:119:1982
    [root@redhat script]#
    [root@redhat script]#sort -t: video.txt 
    A Few Good Men:KL:445:5851
    Alien:HK:119:1982
    Aliens:HK:534:4892
    Boy in Company C:HK:192:1292
    Star Wars:HK:301:4102
    The Hill:KL:63:2972
    Toy Story:HK:239:3972
    [root@redhat script]#
    [root@redhat script]#sort -t: -r video.txt 
    Toy Story:HK:239:3972
    The Hill:KL:63:2972
    Star Wars:HK:301:4102
    Boy in Company C:HK:192:1292
    Aliens:HK:534:4892
    Alien:HK:119:1982
    A Few Good Men:KL:445:5851
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#sort -t: +0 video.txt 
    A Few Good Men:KL:445:5851
    Alien:HK:119:1982
    Aliens:HK:534:4892
    Boy in Company C:HK:192:1292
    Star Wars:HK:301:4102
    The Hill:KL:63:2972
    Toy Story:HK:239:3972
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#sort -t: +1 video.txt 
    Alien:HK:119:1982
    Boy in Company C:HK:192:1292
    Toy Story:HK:239:3972
    Star Wars:HK:301:4102
    Aliens:HK:534:4892
    A Few Good Men:KL:445:5851
    The Hill:KL:63:2972
    [root@redhat script]#
    [root@redhat script]#sort -t: +2 video.txt 
    Alien:HK:119:1982
    Boy in Company C:HK:192:1292
    Toy Story:HK:239:3972
    Star Wars:HK:301:4102
    A Few Good Men:KL:445:5851
    Aliens:HK:534:4892
    The Hill:KL:63:2972
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#sort -t: +2n video.txt 
    The Hill:KL:63:2972
    Alien:HK:119:1982
    Boy in Company C:HK:192:1292
    Toy Story:HK:239:3972
    Star Wars:HK:301:4102
    A Few Good Men:KL:445:5851
    Aliens:HK:534:4892
    [root@redhat script]#
    [root@redhat script]# 
    [root@redhat script]#
    [root@redhat script]#cat video.txt 
    Boy in Company C:HK:192:1292
    Alien:HK:119:1982
    The Hill:KL:63:2972
    Aliens:HK:534:4892
    Star Wars:HK:301:4102
    A Few Good Men:KL:445:5851
    Toy Story:HK:239:3972
    Alien:HK:119:1982
    [root@redhat script]#
    [root@redhat script]#sort -u video.txt 
    A Few Good Men:KL:445:5851
    Alien:HK:119:1982
    Aliens:HK:534:4892
    Boy in Company C:HK:192:1292
    Star Wars:HK:301:4102
    The Hill:KL:63:2972
    Toy Story:HK:239:3972
    [root@redhat script]#
    [root@redhat script]#sort -t: +3 video.txt 
    Boy in Company C:HK:192:1292
    Alien:HK:119:1982
    The Hill:KL:63:2972
    Toy Story:HK:239:3972
    Star Wars:HK:301:4102
    Aliens:HK:534:4892
    A Few Good Men:KL:445:5851
    [root@redhat script]#
    [root@redhat script]#sort -t: -k4 video.txt 
    Boy in Company C:HK:192:1292
    Alien:HK:119:1982
    The Hill:KL:63:2972
    Toy Story:HK:239:3972
    Star Wars:HK:301:4102
    Aliens:HK:534:4892
    A Few Good Men:KL:445:5851
    [root@redhat script]#
    [root@redhat script]#sort -t: -k1 video.txt 
    A Few Good Men:KL:445:5851
    Alien:HK:119:1982
    Aliens:HK:534:4892
    Boy in Company C:HK:192:1292
    Star Wars:HK:301:4102
    The Hill:KL:63:2972
    Toy Story:HK:239:3972
    [root@redhat script]#sort -t: -k2 video.txt 
    Alien:HK:119:1982
    Boy in Company C:HK:192:1292
    Toy Story:HK:239:3972
    Star Wars:HK:301:4102
    Aliens:HK:534:4892
    A Few Good Men:KL:445:5851
    The Hill:KL:63:2972
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#sort -t: -k2 -k4 video.txt 
    Alien:HK:119:1982
    Boy in Company C:HK:192:1292
    Toy Story:HK:239:3972
    Star Wars:HK:301:4102
    Aliens:HK:534:4892
    A Few Good Men:KL:445:5851
    The Hill:KL:63:2972
    [root@redhat script]#
    [root@redhat script]#sort -t: +1 +3 video.txt 
    Alien:HK:119:1982
    Boy in Company C:HK:192:1292
    Toy Story:HK:239:3972
    Star Wars:HK:301:4102
    Aliens:HK:534:4892
    A Few Good Men:KL:445:5851
    The Hill:KL:63:2972
    [root@redhat script]#sort -t: +1 -2 +3 video.txt 
    Boy in Company C:HK:192:1292
    Alien:HK:119:1982
    Toy Story:HK:239:3972
    Star Wars:HK:301:4102
    Aliens:HK:534:4892
    The Hill:KL:63:2972
    A Few Good Men:KL:445:5851
    [root@redhat script]#
    [root@redhat script]#sort -t: +1.2 video.txt 
    Alien:HK:119:1982
    Boy in Company C:HK:192:1292
    Toy Story:HK:239:3972
    Star Wars:HK:301:4102
    A Few Good Men:KL:445:5851
    Aliens:HK:534:4892
    The Hill:KL:63:2972
    [root@redhat script]#
    [root@redhat script]#sort -t: +0.2 video.txt 
    Star Wars:HK:301:4102
    The Hill:KL:63:2972
    A Few Good Men:KL:445:5851
    Alien:HK:119:1982
    Aliens:HK:534:4892
    Boy in Company C:HK:192:1292
    Toy Story:HK:239:3972
    [root@redhat script]#
    [root@redhat script]#sort -t: +0.0 video.txt 
    A Few Good Men:KL:445:5851
    Alien:HK:119:1982
    Aliens:HK:534:4892
    Boy in Company C:HK:192:1292
    Star Wars:HK:301:4102
    The Hill:KL:63:2972
    Toy Story:HK:239:3972
    [root@redhat script]#
    [root@redhat script]#sort -t: -r -k4 video.txt | head -1
    A Few Good Men:KL:445:5851
    [root@redhat script]#
    [root@redhat script]#sort -t: -r -k4 video.txt | head -3
    A Few Good Men:KL:445:5851
    Aliens:HK:534:4892
    Star Wars:HK:301:4102
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#sort -t: -r -k4 video.txt | tail -1
    Boy in Company C:HK:192:1292
    [root@redhat script]#
    Boy in Company C:HK:192:1292
    [root@redhat script]#
    [root@redhat script]#sort -t: -r -k4 video.txt | head 
    A Few Good Men:KL:445:5851
    Aliens:HK:534:4892
    Star Wars:HK:301:4102
    Toy Story:HK:239:3972
    The Hill:KL:63:2972
    Alien:HK:119:1982
    Boy in Company C:HK:192:1292
    [root@redhat script]#
    [root@redhat script]#sort -t: -r -k4 video.txt | tail 
    A Few Good Men:KL:445:5851
    Aliens:HK:534:4892
    Star Wars:HK:301:4102
    Toy Story:HK:239:3972
    The Hill:KL:63:2972
    Alien:HK:119:1982
    Boy in Company C:HK:192:1292
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#cat video.txt 
    Boy in Company C:HK:192:1292
    Alien:HK:119:1982
    The Hill:KL:63:2972
    Aliens:HK:534:4892
    Star Wars:HK:301:4102
    A Few Good Men:KL:445:5851
    Toy Story:HK:239:3972
    [root@redhat script]#
    [root@redhat script]#cat video2.txt 
    111111111111111111111
    222222222222222222222
    333333333333333333333
    [root@redhat script]#
    [root@redhat script]#sort -t: -m video.txt video2.txt 
    111111111111111111111
    222222222222222222222
    333333333333333333333
    Boy in Company C:HK:192:1292
    Alien:HK:119:1982
    The Hill:KL:63:2972
    Aliens:HK:534:4892
    Star Wars:HK:301:4102
    A Few Good Men:KL:445:5851
    Toy Story:HK:239:3972
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#cat /etc/passwd | sort -t: +0 | awk -F":" '{print $1}'
    adm
    apache
    bin
    daemon
    dbus
    ftp
    games
    gdm
    gopher
    haldaemon
    halt
    htt
    lp
    mailnull
    mail
    netdump
    news
    nfsnobody
    nobody
    nscd
    ntp
    operator
    pcap
    root
    rpcuser
    rpc
    rpm
    shutdown
    smmsp
    sshd
    sync
    uucp
    vcsa
    xfs
    yezhaohui2
    yezhaohui   

    2、uniq 
           uniq用来从一个文本文件中去除或禁止重复行。一般uniq假定文件已分类,并且结果正确。我们并不强制要求这样做,如果愿意,可以使用任何非排序本,甚至是无规律行。可以认为 uniq有点像sort命令中唯一性选项。对,在某种程度上讲正是如此,但两者有区别。   
    选项:   
    -u       只显示不重复行。
    -d       只显示有重复数据行,每种重复行只显示其中一行
    -c        打印每一重复行出现次数。
    -fn       n为数字,前n-1个域被忽略。 一些系统不识别-f选项,这时替代使用-nn。   

    命令行实例:
    [root@redhat script]#cat myfile.txt 
    May Day
    May Day
    May Day
    Going Down
    May Day
    [root@redhat script]#
    [root@redhat script]#uniq myfile.txt 
    May Day
    Going Down
    May Day
    [root@redhat script]#
    [root@redhat script]#sort -u myfile.txt 
    Going Down
    May Day
    [root@redhat script]#
    [root@redhat script]#uniq -c myfile.txt 
          3 May Day
          1 Going Down
          1 May Day
    [root@redhat script]#
    [root@redhat script]#uniq -d myfile.txt 
    May Day
    [root@redhat script]#
    [root@redhat script]#cat parts.txt 
    AK123 OP
    DK122 OP
    EK999 OP
    [root@redhat script]#
    [root@redhat script]#uniq -c parts.txt 
          1 AK123 OP
          1 DK122 OP
          1 EK999 OP
    [root@redhat script]#
    [root@redhat script]#uniq -f2 parts.txt 
    AK123 OP
    [root@redhat script]#
    [root@redhat script]#uniq -c -f2 parts.txt 
          3 AK123 OP   

    3、join
        join用来将来自两个分类文本文件的行连在一起。文本文件中的域通常由空格或 tab键分隔,但如果愿意,可以指定其他的域分隔符。一些 系统要求使用join时文件域要少于20,为公平起见,如果域大于20,应使用DBMS系统。   
    选项:
    an         n 为一数字,用于连接时从文件n中显示不匹配行。例如,-a1显示第一个文件的不匹 配行,-a2为从第二个文件中显示不匹配行。
    o n.m    n 为文件号, m为域号。1.3表示只显示文件 1第三域,每个 n,m必须用逗号分隔,如1.3,2.1。
    j n m     n为文件号, m为域号。使用其他域做连接域。
    t 域分隔符    用来设置非空格或tab键的域分隔符。例如,指定冒号做域分隔符-t:。   
    命令行实例:
    [root@redhat script]#cat names.txt 
    M.Golls 12 Hidd Rd
    P.Heller The Acre
    P.Willey 132 The Grove
    T.Norms 84 Connaught Rd
    K.Fletch 23 Woodlea
    [root@redhat script]#
    [root@redhat script]#cat town.txt 
    M.Golls Norwich NRD
    P.Willey Galashiels GDD
    T.Norms Brandon BSL
    K.Fletch Mildenhall MAF
    [root@redhat script]#
    [root@redhat script]#join names.txt  town.txt 
    M.Golls 12 Hidd Rd Norwich NRD
    P.Willey 132 The Grove Galashiels GDD
    T.Norms 84 Connaught Rd Brandon BSL
    K.Fletch 23 Woodlea Mildenhall MAF
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#join -a1 names.txt  town.txt 
    M.Golls 12 Hidd Rd Norwich NRD
    P.Heller The Acre
    P.Willey 132 The Grove Galashiels GDD
    T.Norms 84 Connaught Rd Brandon BSL
    K.Fletch 23 Woodlea Mildenhall MAF
    [root@redhat script]#
    [root@redhat script]#join -a2 names.txt  town.txt 
    M.Golls 12 Hidd Rd Norwich NRD
    P.Willey 132 The Grove Galashiels GDD
    T.Norms 84 Connaught Rd Brandon BSL
    K.Fletch 23 Woodlea Mildenhall MAF
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#join -a1 -a2 names.txt  town.txt 
    M.Golls 12 Hidd Rd Norwich NRD
    P.Heller The Acre
    P.Willey 132 The Grove Galashiels GDD
    T.Norms 84 Connaught Rd Brandon BSL
    K.Fletch 23 Woodlea Mildenhall MAF
    [root@redhat script]#
    [root@redhat script]#join -o 1.1 names.txt  town.txt 
    M.Golls
    P.Willey
    T.Norms
    K.Fletch
    [root@redhat script]#
    [root@redhat script]#join -o 1.2 names.txt  town.txt 
    12
    132
    84
    23
    [root@redhat script]#
    [root@redhat script]#join -o 2.1 names.txt  town.txt 
    M.Golls
    P.Willey
    T.Norms
    K.Fletch
    [root@redhat script]#
    [root@redhat script]#join -o 2.2 names.txt  town.txt 
    Norwich
    Galashiels
    Brandon
    Mildenhall
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#cat names.txt 
    M.Golls 123 aaa
    P.Heller 22 bbb
    P.Willey 132 ccc
    T.Norms 84 ddd
    K.Fletch 45 eee
    [root@redhat script]#
    [root@redhat script]#cat town.txt 
    M.Golls Norwich NRD aaa
    P.Willey Galashiels GDD bbb
    T.Norms Brandon BSL ccc
    K.Fletch Mildenhall MAF eee
    [root@redhat script]#
    [root@redhat script]#join names.txt  town.txt 
    M.Golls 123 aaa Norwich NRD aaa
    P.Willey 132 ccc Galashiels GDD bbb
    T.Norms 84 ddd Brandon BSL ccc
    K.Fletch 45 eee Mildenhall MAF eee
    [root@redhat script]#
    [root@redhat script]#join -j1 3 -j2 4 names.txt  town.txt 
    aaa M.Golls 123 M.Golls Norwich NRD
    bbb P.Heller 22 P.Willey Galashiels GDD
    ccc P.Willey 132 T.Norms Brandon BSL
    eee K.Fletch 45 K.Fletch Mildenhall MAF   

    4、cut   
         cut用来从标准输入或文本文件中剪切列或域。剪切文本可以将之粘贴到一个文本文件。cut一般格式为:   
    cut  [options]  file1  file2   
    选项:
    -c list       指定剪切字符数。
    -f field      指定剪切域数。
    -d            指定与空格和 tab键不同的域分隔符。
    -c            指定剪切范围,如下所示:
    -c1,5-7   剪切第 1个字符,然后是第 5到第7个字符。
    -c1-50      剪切前 50个字符。
    -f格式与-c相同:   
    -f 1 ,5         剪切第1域,第5域。
    -f1,10-12    剪切第1域,第10域到第12域。   
    命令行实例:   
    [root@redhat script]#cat pers 
    P.Jones:Office Runner:ID897
    S.Round:UNIX admin:ID666
    L.Clip:Personl Chief:ID982
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#cut -d: -f1 pers 
    P.Jones
    S.Round
    L.Clip
    [root@redhat script]#
    [root@redhat script]#cut -d: -f2 pers 
    Office Runner
    UNIX admin
    Personl Chief
    [root@redhat script]#
    [root@redhat script]#cut -d: -f3 pers 
    ID897
    ID666
    ID982
    [root@redhat script]#
    [root@redhat script]#cut -d: -f1,3 pers 
    P.Jones:ID897
    S.Round:ID666
    L.Clip:ID982
    [root@redhat script]#
    [root@redhat script]#who
    root     pts/0        Dec  7 05:36 (192.168.245.1)
    root     pts/1        Dec  7 05:51 (192.168.245.1)
    [root@redhat script]#
    [root@redhat script]#who | cut -c1-2
    ro
    ro
    [root@redhat script]#who | cut -c1-4
    root
    root
    [root@redhat script]#
    [root@redhat script]#who | cut -c1-14
    root     pts/0
    root     pts/1   

    5、paste
         paste将按行将不同文件行信息放在一行。缺省情况下paste连接时,用空格或tab键分隔 新行中不同文本,除非指定-d选项,它将成为域分隔符。paste格式为:paste -d -s -file1 file2
    选项:
    -d       指定不同于空格或 tab键的域分隔符。例如用 @分隔域,使用 -d@。
    -s       将每个文件合并成行而不是按行粘贴。
    -         使用标准输入。例如ls -l |paste ,意即只在一列上显示输出。 
    命令行实例:
    [root@redhat script]#cut -d: -f1 pers > pas1
    [root@redhat script]#cat pas1 
    P.Jones
    S.Round
    L.Clip
    [root@redhat script]#
    [root@redhat script]#cut -d: -f3 pers > pas2
    [root@redhat script]#cat pas2
    ID897
    ID666
    ID982
    [root@redhat script]#
    [root@redhat script]#paste pas1 pas2
    P.JonesID897
    S.RoundID666
    L.ClipID982
    [root@redhat script]#
    [root@redhat script]#paste pas2 pas1
    ID897P.Jones
    ID666S.Round
    ID982L.Clip
    [root@redhat script]#
    [root@redhat script]#paste -d: pas2 pas1
    ID897:P.Jones
    ID666:S.Round
    ID982:L.Clip
    [root@redhat script]#
    [root@redhat script]#paste -s pas2 pas1
    ID897ID666 ID982
    P.JonesS.RoundL.Clip   

    6、split
         split用来将大文件分割成小文件。有时文件越来越大,传送这些文件时,首先将其分割可 能更容易。使用 vi或其他工具诸如sort时,如果文件对于工作缓冲区太大,也会存在一些问题。 因此有时没有选择余地,必须将文件分割成小的碎片。

    split命令一般格式:split -output_file-size input-filename output-filename   

         这里output-file-size指的是文本文件被分割的行数。split查看文件时,output-file-size选项指定将文件按每个最多1000行分割。如果有个文件有2800行,那么将分割成 3个文件,分别有1000、1000、800行。每个文件格式为x[aa]到x[zz],x为文件名首字母, [aa]、[zz]为文件名剩 余部分顺序字符组合。   

    命令行实例:
    [root@redhat split]#pwd
    /root/yzh/script/split
    [root@redhat split]#
    [root@redhat split]#ll
    总用量 4
    -rwxrwxrwx  1 root root 84 2011/12/07 07:04:20 split1
    [root@redhat split]#
    [root@redhat split]#cat split1 
    this is line1
    this is line2
    this is line3
    this is line4
    this is line5
    this is line6
    [root@redhat split]#
    [root@redhat split]#split split1 
    [root@redhat split]#ll
    总用量 8
    -rwxrwxrwx  1 root root 84 2011/12/07 07:04:20 split1
    -rw-r--r--  1 root root 84 2011/12/07 07:06:15 xaa
    [root@redhat split]#
    [root@redhat split]#cat xaa 
    this is line1
    this is line2
    this is line3
    this is line4
    this is line5
    this is line6
    [root@redhat split]#
    [root@redhat split]#rm -rf xaa
    [root@redhat split]#ll
    总用量 4
    -rwxrwxrwx  1 root root 84 2011/12/07 07:04:20 split1
    [root@redhat split]#
    [root@redhat split]#split -2 split1 
    [root@redhat split]#ll
    总用量 16
    -rwxrwxrwx  1 root root 84 2011/12/07 07:04:20 split1
    -rw-r--r--  1 root root 28 2011/12/07 07:06:46 xaa
    -rw-r--r--  1 root root 28 2011/12/07 07:06:46 xab
    -rw-r--r--  1 root root 28 2011/12/07 07:06:46 xac
    [root@redhat split]#
    [root@redhat split]#cat xaa && echo ======= && cat xab && echo ======= && cat  xac
    this is line1
    this is line2
    =======
    this is line3
    this is line4
    =======
    this is line5
    this is line6   

    7、tr
         tr用来从标准输入中通过替换或删除操作进行字符转换。tr主要用于删除文件中控制字符 或进行字符转换。使用 tr时要转换两个字符串:字符串 1用于查询,字符串2用于处理各种转换。 tr刚执行时,字符串 1中的字符被映射到字符串 2中的字符,然后转换操作开始。指定字符串1或字符串2的内容时,只能使用单字符或字符串范围。命令格式为:
    tr-c -d -s ["string1_to_translate_from"] ["string2_to_t riannpsulta_te_to" ]  file   
    选项:
    -c       用字符串 1中字符集的补集替换此字符集,要求字符集为 ASCII。
    -d       删除字符串 1中所有输入字符。
    -s       删除所有重复出现字符序列,只保留第一个;即将重复出现字符串压缩为一个字符串。
    Input-file是转换文件名。 虽然可以使用其他格式输入,但这种格式最常用。   

    字符范围:
    [a-z]        a-z内的字符组成的字符串。 
    [A-Z]       A-Z内的字符组成的字符串。 
    [0-9]        数字串。
    /octal       一个三位的八进制数,对应有效的 ASCII字符。
    [O*n]      表示字符 O重复出现指定次数 n。因此 [O*2]匹配OO的字符串。 大部分 tr变种支持字符类和速记控制字符。字符类格式为 [:class],包含数字、希腊字母、空行、小写、大写、 cntrl键、空格、点记符、图形等等。   

    tr中特定控制字符的不同表达方式:
    速记符            含义                  八进制方式
    aCtrl-G         铃声                  07
    Ctrl-H         退格符               10
    fCtrl-L          走行换页            14
    Ctrl-J          新行                 12
    Ctrl-M         回车                 15
                      Ctrl-I tab键       11
    v                  Ctrl-X              30

    命令行实例:(无转换控制字符的例子)
    [root@redhat script]#cat oops.txt 
    And the cowwwwws went homeeeeeee
    Or did theyyyy
    [root@redhat script]#tr -s "[a-z]" < oops.txt 
    And the cows went home
    Or did they
    [root@redhat script]#
    [root@redhat script]#tr -s "[A-Z]" < oops.txt 
    And the cowwwwws went homeeeeeee
    Or did theyyyy
    [root@redhat script]#
    [root@redhat script]#cat oops.txt | tr -s "[a-z]" 
    And the cows went home
    Or did they
    [root@redhat script]#
    [root@redhat script]#cat oops.txt 
    And the cowwwwws went homeeeeeee
    Or did theyyyy
    ssssssssssssssssssssssssssssss
    dd
    11111111111111111111111111
    [root@redhat script]#
    [root@redhat script]#tr -s [" "] < oops.txt 
    And the cowwwwws went homeeeeeee
    Or did theyyyy
    ssssssssssssssssssssssssssssss
    dd
    11111111111111111111111111
    [root@redhat script]#
    [root@redhat script]#tr -s [a-z] < oops.txt 
    And the cows went home
    Or did they
    s
    d
    11111111111111111111111111
    [root@redhat script]#
    [root@redhat script]#tr -s '[a-z]' < oops.txt 
    And the cows went home
    Or did they
    s
    d
    11111111111111111111111111
    [root@redhat script]#
    [root@redhat script]#tr -s '[" "]' < oops.txt 
    And the cowwwwws went homeeeeeee
    Or did theyyyy
    ssssssssssssssssssssssssssssss
    dd
    11111111111111111111111111
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#echo "May Day,May Day,Going Down..." | tr "[a-z]" "[A-Z]"
    MAY DAY,MAY DAY,GOING DOWN...
    [root@redhat script]#
    [root@redhat script]#
    [root@redhat script]#echo "May Day,May Day,Going Down..." | tr "[:lower:]" "[:upper:]"
    MAY DAY,MAY DAY,GOING DOWN...
    [root@redhat script]#
    [root@redhat script]#echo "May Day,May Day,Going Down..." | tr "[A-Z]" "[a-z]"
    may day,may day,going down...
    [root@redhat script]#
    [root@redhat script]#echo "May Day,May Day,Going Down..." | tr "[:upper:]" "[:lower:]"
    may day,may day,going down...
    [root@redhat script]#
    [root@redhat script]#echo "monday123" | tr -c "[a-z]" "[12*]"
    monday
    You have new mail in /var/spool/mail/root
    [root@redhat script]#
    [root@redhat script]#echo "monday12" | tr -c "[a-z]" "[12*]"
    monday
    [root@redhat script]#echo "monday1" | tr -c "[a-z]" "[12*]"
    monday
    [root@redhat script]#echo "monday" | tr -c "[a-z]" "[12*]"
    monday
    [root@redhat script]#
    [root@redhat script]#echo "0000 hdisk5" | tr "[0*4]" "-"
    ---- hdisk5   

  • 相关阅读:
    LD_PRELOAD的偷梁换柱之能
    ATOM & Sublime Text 下MarkDown插件功能比较
    存在
    2017年执行计划
    2015年总结以及2016年计划
    2014年总结以及2015年计划
    asp.net MVC中form提交和控制器接受form提交过来的数据
    2013年回顾及2014年计划
    c# XML序列化与反序列化
    Namenode HA原理详解(脑裂)
  • 原文地址:https://www.cnblogs.com/defias/p/3281717.html
Copyright © 2011-2022 走看看