Linux Learning Summary (18) Several simple text processing tools cut sort TR Split

Source: Internet
Author: User

1 command cut

Used to intercept a field
Format: cut-d ' delimiter ' [-CF] n, N is a number, indicating the first paragraph
-D: followed by a delimiter with a single quotation mark
-C: followed by the first few characters
-F: The first paragraph is followed by
So that means-c,-f option two select one
Example: head-3/etc/passwd |cut-d ': '-F 1

For example head-3/etc/passwd |cut-c 1

-C can also be an interval
For example head-3/etc/passwd |cut-c1-3

-C can also specify characters for several positions individually
For example head-3/etc/passwd |cut-c1,3,4

2 command sort

Used for sorting, formatted as sort [-t delimiter] [-KN1,N2] [-nru], where N1 and N2 are numbers
-T: followed by a separator, the function of the same as the cut of-D
-N: means sorting with pure numbers
-r: Indicates reverse ordering
-U: means to repeat
-KN1,N2: Indicates that the N1 interval is sorted to the N2 interval and can be written only-kn1, that is, the N1 field is sorted
Sort does not have any option to compare the ASCII values from the first character to the last, and then output in ascending order
For example head-4/etc/passwd |sort

-t Specifies the delimiter,-K specifies the area
For example head-4/etc/passwd |sort-t ': '-k3-n

You can also sort on a contiguous area
For example head-4/etc/passwd |sort-t ': '-k3,5-r

3 Command WC

The number of lines, characters, or words used to count the document
-L count rows
-M statistic character number
-W Statistic Word number

4 command Uniq

Used to delete duplicate rows, if sorting is required
-C to count the number of rows to repeat
We write a test.txt to understand the

5 Command Tee

Tee with pipe character is similar to redirection, but the specific gravity of one more function, you can write the file to the target file, you can also print it out.
Compare these two sentences: head-3/etc/passwd > A.txt
head-3/etc/passwd |tee B.txt

6 Command TR

Used to replace characters, often used to manipulate special symbols in a document
-D means to delete a character
-S means to delete duplicate characters
For two examples, lowercase replace uppercase
Head-2/etc/passwd |tr ' [A-z] ' [A-z] '

Replace a character
Head-2/etc/passwd |tr ' o ' o '

7 Command Split

User-cut documents, common options are-b,-l
-B: Specify file size cut in byte
For example, we cut a 3M file for 3 copies.

Below we cut according to line,/ETC/PASSWD has 21 lines, we cut it by line to three parts

Linux Learning Summary (18) Several simple text processing tools cut sort TR Split

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.