Shell special characters, Cut,sort,wc,uniq,tee,tr,split command

Source: Internet
Author: User

Shell special Characters
    • * Any of the characters
    • ? Any one character
    • #注释字符
    • \ de-Semantic characters
    • | pipe character
    • $ variable prefix,!$ combination, regular inside means end of line
    • Multiple commands are written to one line, separated by semicolons.
    • ~ User home directory, regular expression indicates match
    • & put the command behind the command and throw it backstage.
    • \>,>>,2>,2>>,&> (correct and error redirect)
    • [] One of the specified characters, [0-9],[A-ZA-Z],[ABC]
    • || When the preceding command succeeds without executing the following, the preceding is unsuccessful before executing the
    • && when the previous command does not succeed do not execute behind, the previous success is executed behind OH
Cut command
    • Intercept string
    • -d Specifies the delimiter,-f specifies to intercept the specified field number, and-C to specify the first few characters
      [[email protected] ~]# cat /etc/passwd |head -2root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologin[[email protected] ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1rootbin[[email protected] ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1,2root:xbin:x[[email protected] ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1-3root:x:0bin:x:1[[email protected] ~]# cat /etc/passwd |head -2 |cut -c 4t:
Sort command
  • ASCII sorting, alphabetical order
    [[email protected] ~]# sort /etc/passwdadm:x:3:4:adm:/var/adm:/sbin/nologinaming:x:1000:1000::/home/aming:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologinchrony:x:997:995::/var/lib/chrony:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologin
  • -N is numerically sorted, letters and special symbols default to zero
      [[email protected] ~]# sort-n 1.txt[]adm:x:3:4:adm:/var/adm:/sbin/ nologinbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinhalt:x:7:0:halt:/sbin:/sbin/ Haltlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:o perator:/root:/sbin/nologinroot:x:0:0:root:/root:/bin/bash*sdshdjhjshutdown:x:6:0:shutdown:/sbin:/sbin/ SHUTDOWNSYNC:X:5:0:SYNC:/SBIN:/BIN/SYNC22AAA2222222AAAAAA111344442222211114234234252SDADHKAJHKJ  
  • -R Reverse Order
    [[email protected] ~]# sort -nr 1.txt4234234252sdadhkajhkj222221111111344442222222aaaaaa22aaasync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdown*sdshdjhjroot:x:0:0:root:/root:/bin/bashoperator:x:11:0:operator:/root:/sbin/nologinmail:x:8:12:mail:/var/spool/mail:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinhalt:x:7:0:halt:/sbin:/sbin/haltdaemon:x:2:2:daemon:/sbin:/sbin/nologinbin:x:1:1:bin:/bin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologin}
  • -T delimiter,-kn1/-kn1,n2
WC command
    • -L count rows
      [[email protected] ~]# wc -l 1.txt 23 1.txt
    • -M statistic character number
    • -W statistic phrase number, separated by whitespace character
Uniq command
    • Go to Heavy,-C statistics line number of rows to heavy
      [[email protected] ~]# sort 2.txt 111231232abcabc 111,222[[email protected] ~]# sort 2.txt |uniq11232abcabc 111,222[[email protected] ~]# sort 2.txt |uniq -c  1   2 1  2 123  1 2  1 abc  1 abc 111,222
Tee command
    • Similar to >, redirects are also displayed on the screen
      [[email protected] ~]# sort 2.txt |uniq -c > a.txt [[email protected] ~]# sort 2.txt |uniq -c |tee a.txt 2 12 1231 21 abc1 abc 111,222
    • Add-A and >> similar, append and display appended content
TR Replacement Character
[[email protected] ~]# echo "aminglinux" |tr ‘[al]‘ ‘[AL]‘AmingLinux[[email protected] ~]# echo "aminglinux" |tr ‘[a-z]‘ ‘[A-Z]‘AMINGLINUX
Split command
    • -B is cut with file size, followed by a filename, and you can specify the post-cut filename prefix later
    • -L is cut with the number of rows, followed by the file name, and can be later specified after the cut filename prefix
      [[email protected] test]# split -b 100k q.txt abc.[[email protected] test]# lsabc.aa  abc.ab  abc.ac  q.txt[[email protected] test]# split -l 1000 q.txt abc.[[email protected] test]# lsabc.aa  abc.ab  abc.ac  abc.ad  abc.ae  abc.af  abc.ag  q.txt
Test

Shell special characters, Cut,sort,wc,uniq,tee,tr,split command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.