Linux command for processing text content

Source: Internet
Author: User
Tags processing text
Linux commands for processing text content recently learned some commands for processing text content. I will summarize them today for future review! The following command only lists some common parameters. uniq command can delete duplicate lines in the file without adding parameters (these duplicate lines must be adjacent and not adjacent... linux commands for processing text content recently learned some commands for processing text content. I will summarize them today for future review! The following command only lists some common parameters. the uniq command can delete duplicate lines in the file without adding parameters (these duplicate lines must be adjacent and cannot be removed ). -c adds the number of times each line appears in the input file before the output line.-d only displays duplicate rows.-u only displays rows that have not been repeated. Command mode: uniq [parameter] File. this is a simple example! The sed command sort compares each line of the file with each other as a unit. the comparison principle is to compare the lines following the first character by ASCII code value in sequence, finally, output them in ascending order. Sort does not add parameters in ascending order-r in reverse order;-n prevents 10 from leading to 2;-t ":" defines the separator as Colon;-k 3 selects the third part. example: sort-rn-t:-k 3/etc/passwd to ":" split passwd to sort the lines in the file in descending order of the third part. the cut command can extract text columns from a text file or text stream. -D: followed by separator characters. Used with-f;-f: splits a piece of information into segments based on the-d separator, and uses-f to get the meaning of the segments; cat/etc/passwd | cut-D': '-f 1, 3 use: to split the passwd file and retrieve the first and third columns of the passwd file cat/etc/passwd | cut-D ': '-f 1-3 use: split the passwd file and retrieve the first column of the passwd file to the third column of head and tail commands! The most basic options are cat, more, and less. 1. if you only want to view the first five lines of the file, you can use the head command, such as head-5/etc/passwd 2. if you want to view the last 10 lines of the file, you can use the tail command, such: tail-10/etc/passwd or tail-n 10/etc/passwd tail-f/var/log/messages parameter-f keeps tail reading the latest content, in this way, you can use Ctrl + c to terminate real-time monitoring! 3. view the middle part of the file, you can use the sed command, such as: sed-n'5, 10p'/etc/passwd so that you can only view the join command of lines 5th to lines 10th of the file. the join command can merge and output the content of two files in the same format! -A1 indicates displaying unmatched rows in the first file, that is, left join-a2 indicates displaying unmatched rows in the second file, that is, right join-o 1.1 2.1-o is the output parameter, and 1.1 indicates the first column of the output first file; 2.1 indicates that the first column of the second file-t "|" is the delimiter parameter, indicating that | as the domain separator-j 1.1-j is the parameter of the connected field, the first column of the first file is associated with the first column of the second file.
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.