Shell Special Symbol/cut,sort,wc,uniq,tee,tr,split command

Source: Internet
Author: User

Shell Special Symbol Cut command

Shell Special Symbols

* *任意个任意字符* ?任意一个字符* #注释字符* \脱义字符* |管道符

Command cut
cut is used to intercept a field in the form of: #cut –d ' separator character ' [-cf]n,n is a number.

Options:
- D is followed by a delimiter, and delimited characters are enclosed in single quotes.
- c is followed by the number of characters.
The number of blocks is followed by- F .

[Email protected] ~]# cat/etc/passwd |head-2
Root:x:0:0:root:/root:/bin/bash
Bin:x:1:1:bin:/bin:/sbin/nologin
[[email protected] ~]# cat/etc/passwd |head-2 |cut-d ":"-F 1
Root
Bin
[Email protected] ~]# cat/etc/passwd |head-2 |cut-d ":"-F
Root:x
Bin:x
[[email protected] ~]# cat/etc/passwd |head-2 |cut-d ":"-F 1-3
root:x:0
Bin:x:1
[Email protected] ~]# cat/etc/passwd |head-2 |cut-c 4
T

Sort_wc_uniq command

Sort command
sort is used for sorting, in the format sort[-t delimiter][-kn1,n2][-nru], where N1 and N2 refer to numbers, and other options have the following meanings.

Options:
- n means sorting with pure numbers
- R indicates reverse ordering
- u means to repeat
-T followed by a split character, as with the-D option of cut
The -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

[[Email protected] Document]# sort 1.txt
<
>
[
1111
11222
22333
444444411
Adm:x:3:4:adm:/var/adm:/sbin/nologin
[[Email protected] Document]# Sort-n 1.txt//letter defaults to 0
<
>
[
Adm:x:3:4:adm:/var/adm:/sbin/nologin
1111
11222
22333
444444411
[[Email protected] Document]# SORT-NR 1.txt//reverse order Display
444444411
22333
11222
1111
Adm:x:3:4:adm:/var/adm:/sbin/nologin
[
>
<

WC command

The WC command is used to count the number of lines, characters, or words of a document. The common options for this command are:
- L(count rows)
- M (Number of statistics characters)
- W(number of statistical words)

[[Email protected] Document]# cat 2.txt
Hello World
111
222
111,222
[Email protected] document]# wc-l 2.txt
4 2.txt
[Email protected] document]# wc-m 2.txt
2.txt
[Email protected] document]# wc-w 2.txt
5 2.txt

Uniq command
uniq used to delete duplicate rows
Options:
- C Count repeats

[[Email protected] Document]# cat 2.txt
Hello World
111
222
111,22
222
Aa
345
222
Aa
456
456
[[Email protected] Document]# sort 2.txt |uniq-c
1 111
1 111,22
3 222
1 345
2 456
2 AA
1 Hello World

Tee_tr_split command

Command Tee
Tee followed by the file name, its role is similar to redirect, the specific gravity of a function, the file is written to the following file and displayed on the screen, usually used for pipe characters | After.
Options
-a added meaning

[[Email protected] Document]# sort 2.txt |uniq-c |tee 4.txt
1 111
1 111,22
3 222
1 345
2 456
2 AA
1 Hello World
[[Email protected] Document]# sort 2.txt |uniq-c |tee-a 4.txt
[[Email protected] Document]# cat 4.txt
1 111
1 111,22
3 222
1 345
2 456
2 AA
1 Hello World
1 111
1 111,22
3 222
1 345
2 456
2 AA
1 Hello World

Command TR
TR for substitution characters

[[Email protected] Document]# echo "Asklinux" |tr ' [al] ' [Al] '
Asklinux
[[Email protected] Document]# echo "Asklinux" |tr ' [A-z] ' [A-z] '
Asklinux

Command split

Split is used to cut documents.

Options:
- b means that the document is split by size in bytes
- L to divide the document by the number of rows

[[Email protected] Demo]# du-sh 5.txt
652K 5.txt
[[Email protected] Demo]# split-b 200k 5.txt
[[Email protected] Demo]# ls
5.txt Xaa xab xac xad
[[Email protected] Demo]# split-l 4000 5.txt
[[Email protected] Demo]# ls
5.txt xaa xab xac xad xae

Shell special symbol under
* $变量前缀,!$组合,正则里面表示行尾* ;多条命令写到一行,用分号分割* ~用户家目录,正则表达式表示匹配符* &放到命令后面,会把命令丢到后台* >  >>   2>  2>>  &>* []指定字符串中的一个,[0-9],[a-zA-Z][abc] * ||和&&,用于命令之间

[[Email protected] Demo]# rm-f xa*; LS//SEMICOLON usage
5.txt

[[Email protected] document]# ls 1.txt | | Wc-l 2.txt//When the previous command is executed correctly, the following command will no longer execute
1.txt
[[Email protected] document]# ls 1.txt && wc-l 2.txt//When the previous command is executed correctly, the following command executes
1.txt
2.txt

Shell Special Symbol/cut,sort,wc,uniq,tee,tr,split command

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.