Bash text viewing and processing tools

Source: Internet
Author: User

Text viewing and processing tools:
WC [OPTION] FILE ...
-C: Number of bytes
-L: Number of rows
-W: number of words
W.H.O. | Wc-l: View current number of users

Cut [OPTION] FILE ...
-D CHAR: Specify field delimiter
If this option is not added, the default is separated by a space
-F #|#-#|#,#: Specify the fields to display

Cut-d:-F 1/etc/password
Cut the/etc/password file with a colon and display the first field
That is, lists the first field in the current/etc/password, the user name

Cut-d:-F 1,3/etc/password
Show first and third fields of colon split

Cut-d:-F 1-3/etc/password
Show first to third field of colon split

Cut-f 1-3/etc/password
Default first to third field separated by a space separator

Sort [OPTION ...] FILE ...
-N: Sort by numeric size
-R: Reverse order
-F: Ignore character case
-T CHAR: Specify field delimiter
-K #: Specifies the field to use for sorting
-U: Duplicate rows are retained only once

Cut-d:-F 3/etc/password | Sort-n
Sort by the size of the value in the third column of the/etc/password file

Sort-n/etc/password
Sort the letters at the beginning of the line

Sort-t:-K 3-n/etc/password
Sort the third field after a colon split

Sort-n-u/tmp/test
Duplicate rows are displayed only once
Uniq [OPTION ...] FILE ...
-C: Shows the number of occurrences of each line;
-D: Show only duplicate rows;
-U: Displays only rows that have not been duplicated;

Uniq-c/tmp/test
Uniq-d/tmp/test
Uniq-u/tmp/test

Exercise: Remove the IP address from the ifconfig eth0 result;
# ifconfig Eth0 | head-2 | Tail-1 | Cut-d:-F 2 | Cut-d ""-F 1

Bash text viewing and processing tools

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.