Text file commands (Wc,cut,sort,uniq) and common parameters

Source: Internet
Author: User


WC Word Count

WC [OPTION] ... [FILE] ...

-L,--lines shows the number of rows

-W,--words displays the number of words

-C,--bytes shows the number of bytes

- L,--max-line-length prints the length of the longest line.


eg

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5B/E4/wKioL1UWFEDTIBfiAAC3iBqHOLg787.jpg "title=" wc.jpg "alt=" Wkiol1uwfedtibfiaac3ibqholg787.jpg "/>




Cut file Extraction command

Official explanation: Remove sections from all line of files

Select a section from each line in the file

According to the official explanation, you know that cut is the object of every action.


Usage: Cut OPTION ... [FILE] ...

Common parameters: (Other parameters please refer to the command manual: Man cut)

-d ', indicating the separator

-F, indicating the field to keep;

-f#:

Single: #

Discrete multiple: #,#,#

Number of consecutive: #-#

eg:1, only displays the UID, GID of the user in the/etc/passwd

#head/etc/passwd | Cut-d:-f1,3,4

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5B/E4/wKioL1UWFOaT9dHMAACeKsNJ1kQ238.jpg "title=" cut Using the. jpg "alt=" wkiol1uwfoat9dhmaaceksnj1kq238.jpg "/>

2. List the user names of all logged-in users on the current system;

Note: The same user logged in multiple times, only one time can be displayed;

#:who|cut-d '-f1|sort-u

Sort is a command that sorts a text file (by default, sorted by character)

Official explanation: Sort lines of the text files

--Distinguish lines of text files

Sort is also the object that is handled by the behavior

Usage:sort [OPTION] ... [FILE] ...

Common parameters:

-R: Reverse order:

-F: Ignores character case;

-T: Specify field Delimiter

-K: Choose which interval to sort by

-N: Numeric size sorting

-U: Go back to "focus" after sorting


Eg:1, sort/etc/passwd by uid size

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5B/EA/wKiom1UWDpvQV2NkAAF4292oFL4369.jpg "title=" sort sort. jpg "alt=" wkiom1uwdpvqv2nkaaf4292ofl4369.jpg "/>

2. The/etc/passwd file is sorted by UID size, and only the user name and UID number are displayed

SORT-T:-k3-n/etc/passwd |cut-d:-f3,1

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5B/E4/wKioL1UWEHHDGY0lAACay8wIiMk385.jpg "title=" Cut.jpg "alt=" Wkiol1uwehhdgy0laacay8wiimk385.jpg "/>



Uniq: Go to the heavy command

Official explanation: report or omit repeated lines

--- to display or delete duplicate rows

Common parameters:

-I: Ignore case

-D: Show only duplicate rows

-u: Show only rows that appear once

-C: Displays the number of occurrences of each row after the reset

eg

Create a Aa.txt file, and then sort the file in descending order by the number of repetitions

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5B/EA/wKiom1UWEbuh5G0JAABiQbAdfrc899.jpg "title=" Vim.jpg "alt=" Wkiom1uwebuh5g0jaabiqbadfrc899.jpg "/>

# sort A.txt | uniq-c | SORT-R-N//After the file has been de-weighed, descending by the number of occurrences


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5B/EA/wKiom1UWEnfR9YpPAABoD4RXUQw160.jpg "title=" Uniq. JPG "alt=" wkiom1uwenfr9yppaabod4rxuqw160.jpg "/>


==========================

File de-weight method:

1, sort-u File to go heavy

2. Uniq File

===============================


This article is from the "impermanence" blog, please be sure to keep this source http://1inux.blog.51cto.com/10037358/1625911

Text file commands (Wc,cut,sort,uniq) and common parameters

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.