Linux--note Shell common commands for cut, sort, unqi, tee, TR, split, and Shell Connectors && | |

Source: Internet
Author: User
Tags rows count

1. Cut

Used to segment a file

Cut-d ' delimiter ' [-CF] n

-d Specifies the delimiter followed by single quotation marks.

-F Specify paragraph

-C is followed by a number that indicates the intercept of the first few characters, followed by a number area, which indicates the interception from a few to several.

[Email protected] ~]# cut-d:-F 3/ETC/PASSWD

[Email protected] ~]# cut-d:-F 3,4/ETC/PASSWD

[Email protected] ~]# cut-c 10/etc/passwd

[Email protected] ~]# cut-c 1-10/etc/passwd

2. Sort (sorting by default is sorted by ASCII value)

Sort [-t delimiter] [-KN1,N2] [-nru]

-T delimiter: a meaning of function with cut

-N Sorts the default ascending order using a pure number

-R reverse Sort, number descending

-U to repeat

-KN1,N2: Sorted by N1 interval to N2 interval, you can write only kn1, that is, only the N1 field is sorted.

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

[Email protected] ~]# sort-t:-k3/etc/passwd

[Email protected] ~]# sort-t:-k3-n/etc/passwd

[[email protected] ~]# sort-t:-k3,5-n/etc/passwd specified range

[Email protected] ~]# sort-t:-k3,5-r-n/etc/passwd

User1:x:510:510::/home/user1:/bin/bash

User2:x:508:500::/home/user3:/sbin/nologin

[Email protected] ~]# sort-u 2.txt

[[email protected] ~]# Sort-nu 2.txt-nu when used together, multiple strings or characters are treated as a number, displaying only one string or character.

Sort, the-n option will treat all the letters as 0, add a-u to repeat, and, of course, a string or character.

3. WC

Wc-l (calculated Row)-W (word)-m (size is the number of characters)

[Email protected] ~]# wc-l 1.txt 2.txt

2 1.txt

2.txt

24 Total dosage

[[email protected] ~]# wc-w 1.txt (one word for one separator)

6 1.txt

[email protected] ~]# cat 1.txt

LS: unreachable 11111: No file or directory

LS: unreachable 11111: No file or directory

[Email protected] ~]# wc-m 1.txt

1.txt

[[email protected] ~]# echo "12345" |wc-m line break is also a character

6

WC-C,--bytes output bytes count

-M,--chars statistics of output characters

-L,--lines output rows count

-W,--words print the word counts is a few words in the document

4, Uniq and Tee

Uniq to repeat and calculate how many rows to repeat, a function more than sort-u.

UNIQ-C statistics repeat the number of rows, and write the number of lines in front, the drawback is that if the duplicate two characters are not together, it is impossible to judge the repetition needs to be sorted first.

[Email protected]nux ~]# uniq-c 2.txt

[Email protected] ~]# sort 2.txt|uniq-c

If you do not add the-c option, it is consistent with sort-u.

Tee followed by file name, similar to redirect, but weighted more than one function, the file is written in the following file and also displayed on the screen

[Email protected] ~]# echo "123" > 1.txt

[email protected] ~]# cat 1.txt

123

[Email protected] ~]# echo "11111" |tee 1.txt

11111

[Email protected] ~]# echo "123" > 1.txt

[email protected] ~]# cat 1.txt

123

[Email protected] ~]# echo "11111" |tee 1.txt

11111

Tee-i using append mode for redirection


Single quotes all the special symbols will become ordinary symbols, such as ' 123$a ' in which a $ A is not a reference variable, if you use double quotation marks can refer to the variable "123$a" I give a specific example:

[Email protected] ~]# a=9; Echo ' 123$a '; b=8; echo "123$b"

123$a

1238


5. TR and Split

TR is used to replace characters, and special symbols are handled in common writing documents.

tr-d Delete a character, and-D followed by the character to be deleted

-S remove repeated characters

Note: substitution, deletion, and deduplication are for a single character and are not used for a string.

[[email protected] ~]# ls *.txt | Tr ' A-Z ' A-Z

123.TXT

#1. TXT

1.TXT

2.TXT

3.TXT

A.TXT

[[email protected] ~]# echo "HFDUFEURH273498834NDLGJ" |tr ' h ' h '

Hfdufeurh273498834ndlgj

[Email protected] ~]# echo "hfdufeurh273498834ndlgj" |tr ' abcfd ' abcfd '

Hfdufeurh273498834ndlgj


Split for cutting documents

Split-b the document according to size, in bytes (to write in M,k, specify such as Split-b 100m/100k)

-L split document by row

[[email protected] split_dir]# ls

Anaconda-ks.cfg

[Email protected] split_dir]# wc-l anaconda-ks.cfg

Anaconda-ks.cfg

[Email protected] split_dir]# split-l anaconda-ks.cfg

[[email protected] split_dir]# ls

Anaconda-ks.cfg Xaa xab xac xad

[Email protected] split_dir]# wc-l x*

Ten XAA

Ten Xab

Ten Xac

2 Xad

32 Total dosage

[Email protected] split_dir]# DU-SB anaconda-ks.cfg

943 Anaconda-ks.cfg

[Email protected] split_dir]# Split-b anaconda-ks.cfg

[Email protected] split_dir]# LS-LH x*

-rw-r--r--1 root root 100 January 6 23:29 Xaa

-rw-r--r--1 root root 100 January 6 23:29 Xab

-rw-r--r--1 root root 100 January 6 23:29 Xac

-rw-r--r--1 root root 100 January 6 23:29 Xad

-rw-r--r--1 root root 100 January 6 23:29 xae

-rw-r--r--1 root root 100 January 6 23:29 Xaf

-rw-r--r--1 root root 100 January 6 23:29 XAG

-rw-r--r--1 root root 100 January 6 23:29 Xah

-rw-r--r--1 root root 100 January 6 23:29 Xai

-rw-r--r--1 root root 43 January 6 23:29 Xaj

You can give the split file commands such as:

[Email protected] split_dir]# split-l anaconda-ks.cfg new_

[[email protected] split_dir]# ls

Anaconda-ks.cfg new_ab new_ad xab xad xaf xah Xaj

New_aa new_ac xaa xac xae xag Xai

6. Connector in Shell && | |

&& the left command executes successfully before the right command is executed

|| The left command does not execute successfully until the right command is executed.

; The left command executes successfully or the right command executes

[[email protected] ~]# ls 1.txt && ls 2.txt

1.txt

2.txt

[[email protected] ~]# ls 10.txt && ls 2.txt

LS: Unable to access 10.txt: No file or directory

[[email protected] ~]# ls 1.txt | | LS 20.txt

1.txt

[[email protected] ~]# ls 10.txt | | LS 2.txt

LS: Unable to access 10.txt: No file or directory

2.txt

[[email protected] ~]# ls 1.txt | | LS 2.txt

1.txt

[email protected] ~]# ls 10.txt; LS 2.txt

LS: Unable to access 10.txt: No file or directory

2.txt

[email protected] ~]# ls 1.txt; LS 2.txt

1.txt

2.txt





Linux--note Shell common commands for cut, sort, unqi, tee, TR, split, and Shell Connectors && | |

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.