Use of the cut sort tee and Uniq commands in Linux systems

Source: Internet
Author: User

Use-----split for cut commands

 [[email protected] wang]# cut -d  ': '   The-f 1 passwd1 |head -n3  //cut command is used for cutting. -D followed by    delimited, enclosed in single quotation marks  root                                                              //-F specifies the paragraph. The first segment after the delimiter is split  bindaemon  [[email protected] wang]# cut -c1 passwd1  |HEAD -N 3     //CUT specifies a number after which to intercept the first few characters  rbd  [[email  protected] wang]# cut -c1-5 passwd1 |head -n 3   // The cut is followed by a number field that represents the block from a few to a few characters  root:bin:xdaemo 

Sort command using-----sorting

/* Several options for the sort command:-T delimiter: The function is the same as the-D option after cut-N: Use a pure digital row-r: Reverse Sort-u: to repeat the-KN1.N2: the interval is sorted to the N2 interval, or you can write-kn1, that is, sort N1 fields.

 [[email protected] wang]# head -n5 passwd1 |sort   // If sort does not have any options, sort backwards from the first character, followed by ASCII values, and finally arrange them in ascending order  adm:x:3:4:adm:/var/adm:/sbin/nologinbin:x:1:1:bin:/bin:/ sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinroot:x:0:0:root:/ Root:/bin/bash[[email protected] wang]# head -n5 passwd1 |sort -t: -k3 After  -n  //-t is the delimiter, the third row is sorted,-n pure digit sort  root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/ nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/ sbin/nologin[[email protected] wang]#  head -n5 passwd1            //take a look at the first 5 lines of the passwd file  root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin :/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var /spool/lpd:/sbin/nologin[[email protected] wang]#  head -n5 passwd1 |sort -n -u   //the first 5 rows with a purely numeric sort &nbsp, and then in the de-duplication    (sort for-n-Purely numeric sort, the system will treat all the letters as 0 root:x:0:0:root:/root:/bin/bash                            //plus A-u to repeat, there will be only one line left

/*uniq is used to repeat the line, the most common option is only one-C: Statistics duplicate rows, and write the number of lines in front */

[[email protected] ~]# VIM test.c//use VIM to open a file, write several numbers 111222333222444333~[[email protected] ~]# uniq test.c//Direct with U Niq command, found that the file did not change 111222333222444333[[email protected] ~]# sort test.c |uniq//First sort, then in Uniq, so use Uniq if you have to sort the files and then repeat      111222333444[[email protected] ~]# sort test.c |uniq-c//Plus-c option, the number of repeated rows is displayed in front of that line 1 111 2 222 2 333 1 444

The tee command, followed by the filename/* is similar to redirection ">", but the specific weighting is a feature that is also displayed on the screen while the file is written to the back of the file */

[[email protected] ~]# echo  "aaaaaaaaaa"  >test.c  //Redirect to test.c file  [ [email protected] ~]# cat test.c       //displays information after redirection        aaaaaaaaaa    [[email protected] ~]#  echo  "BBBBBBBB"  |tee test.c   //tee the result of the operation, the content to be written on the screen display     The     BBBBBBBB  TR and split command    /*tr are used to replace characters and are commonly used to handle special characters appearing in documents:-D: Delete a character,- D followed by the character to be deleted   -s: Remove the duplicate characters */    [[email protected] ~]# head -n  2 /root/wang/passwd1 |tr  ' [A-z] '   ' [A-z] '   //replace the first two lines of the file with uppercase letters         root:x:0:0:root:/root:/bin/bash      bin:x:1:1:bin :/bin:/sbin/nologin    [[email protected] ~]# head -n 2 / Root/wang/passwd1 |tr  ' A '   ' a '         //convert lowercase A in file to uppercase ' a '           root:x:0:0:root:/root:/bin/bAsh         bin:x:1:1:bin:/bin:/sbin/nologin     split for cutting documents    //         [[email protected] wang]# ls           passwd1 [[email protected] wang]# split -b  500 /root/wang/passwd1   //cutting Documents,-B option to cut documents by size in byte  [[email protected]  wang]# ls     //If split does not specify a target file name, it will be xaa xab ... Such filenames to access the cut file          passwd1  xaa  xab   xac     [[email protected] wang]# split -b 500  /root/wang/passwd1 123  //Specify the file name       [[email protected] wang]# ls      123aa  123ab  123ac  passwd1  xaa  xab  xac      [[email protected] wang]# wc -l passwd1  // See how many lines a document has in common         29 passwd1        [[email protected] wang]# split -l 10 passwd1    //- L represents the number of rows to be cut by the document       [[email protected] wang]# wc -l *        //  View post-cut documents        29  passwd1      10 xaa      10 xab  Total amount of      9 xac      58 


Use of the cut sort tee and Uniq commands in Linux systems

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.