Linux command Rollup (WC, cut, sort, uniq)

Source: Internet
Author: User
Tags gopher

1. WC: number of bytes, words, and lines of statistics files

format: WC [OPTION] ... [FILE] ...

Wc[option] ...--files0-from=f

Parameters:

- C : Count bytes

- M : Statistics of characters

- L : Count Rows

- W : Counting Words

Example:

[Email protected] ~]# WC abc.txt

27367 abc.txt------- à ( number of lines of words bytes file name )

[Email protected] ~]# wc-l abc.txt

abc.txt--------- à ( number of rows file name )

[Email protected] ~]# wc-c abc.txt

367 abc.txt------ à (number of bytes file name)

2. Cut : Choose the information we want from the file

format: Cut OPTION ... [FILE] ...

Parameters:

- b : Split in bytes

- C : Split in a character unit

- D : Tab Split by default

- F : With - D used together to specify which area to display

Example:

[Email protected] ~]# CAT/ETC/PASSWD

Root:x:0:0:root:/root:/bin/bash

Bin:x:1:1:bin:/bin:/sbin/nologin

Daemon:x:2:2:daemon:/sbin:/sbin/nologin

Adm:x:3:4:adm:/var/adm:/sbin/nologin

Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

Sync:x:5:0:sync:/sbin:/bin/sync

Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

Halt:x:7:0:halt:/sbin:/sbin/halt

Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

Uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

Operator:x:11:0:operator:/root:/sbin/nologin

Games:x:12:100:games:/usr/games:/sbin/nologin

Gopher:x:13:30:gopher:/var/gopher:/sbin/nologin

Ftp:x:14:50:ftp User:/var/ftp:/sbin/nologin

Nobody:x:99:99:nobody:/:/sbin/nologin

Vcsa:x:69:69:virtual Console Memoryowner:/dev:/sbin/nologin

Saslauth:x:499:76:saslauthduser:/var/empty/saslauth:/sbin/nologin

Postfix:x:89:89::/var/spool/postfix:/sbin/nologin

Sshd:x:74:74:privilege-separated Ssh:/var/empty/sshd:/sbin/nologin

Lin:x:555:555::/home/lin:/bin/bash

[Email protected] ~]# CAT/ETC/PASSWD | Cut-d:-f7

/bin/bash

/sbin/nologin

/sbin/nologin

/sbin/nologin

/sbin/nologin

/bin/sync

/sbin/shutdown

/sbin/halt

/sbin/nologin

/sbin/nologin

/sbin/nologin

/sbin/nologin

/sbin/nologin

/sbin/nologin

/sbin/nologin

/sbin/nologin

/sbin/nologin

/sbin/nologin

/sbin/nologin

/bin/bash

[Email protected] ~]#

3. Sort : Sort the contents of a file

format: sort [OPTION] ... [FILE] ...

Sort [OPTION] ...--files0-from=f

Parameters:  

- u Delete the duplicate parts

- bignores the space characters that begin before each line.
-CCheck that the files are sorted in order.
-Fwhen sorting, ignores uppercase and lowercase letters.
-Mthe front3the letters are sorted according to the abbreviation of the month.
-Nsorts according to the size of the numbers.
-o<Output File>The sorted result is stored in the specified file.
-Rsorted in reverse order.
-t<Delimited characters>Specifies the field separator character to use when sorting.
-KChoose which interval to sort by.

Example: [email protected] ~]# sort 1abc.txt

Abcd

Abcd

Abcd

Abcdd

Abcdd

Acbd

Ccce

Def

Efg

Efg

Efgg

Ghi

Hijk

Hijk

Hijkk

Jklc

Lmn

Lmn

Lmnn

Opqq

Rst

Uvvv

[Email protected] ~]# sort-u!$

Sort-u 1abc.txt

Abcd

Abcdd

Acbd

Ccce

Def

Efg

Efgg

Ghi

Hijk

Hijkk

Jklc

Lmn

Lmnn

Opqq

Rst

Uvvv

[Email protected] ~]#

4. Uniq : Delete duplicate content, leaving only one

format: uniq [OPTION] ... [INPUT [OUTPUT]]

Parameters:

- C : Displays the number of times the file content appears at the beginning of the display

- D : Show duplicate rows only

- u : Show rows that are not duplicated

Example:

[Email protected] ~]# Sort 1abc.txt | Uniq-d

Abcd

Abcdd

Efg

Hijk

Lmn


This article is from the "Summer Month" blog, please make sure to keep this source http://lkc0110.blog.51cto.com/3410558/1689703

Linux command Rollup (WC, cut, sort, uniq)

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.