8.10-8.13 Shell Special Symbol

Source: Internet
Author: User

8.10 Shell Special symbol Cut command

Special symbols (top):

A 1.* represents 0 or more arbitrary characters.

2. Represents only one arbitrary character ( whether it is a number or a letter, as long as it can be matched. )

3.# This symbol in Linux indicates the meaning of the comment description, that is, The content behind the # Linux ignored.

4.\ A caret character that restores the following special symbol (for example, "*") to a normal character.

5.| pipe character, which is the function of dropping the result of the preceding command to the command following the symbol. The following commands, which are mentioned here, are not available for all commands, and are commonly used for document operations such as Cat, less, head, tail, grep, cut, sort, WC, uniq, tee, tr, split, SED, awk, and so on.

wc-l used to calculate how many rows a document has.

Command: Cut:

Used to intercept a field

Syntax: cut-d ' delimited characters ' [-CF] n here The n is the number

-D: followed by delimited characters, separated by single quotation marks

-C: followed by the first few characters

-F: The next section is followed by the number of blocks

-D followed by the delimiter character, where a colon is used as the split character, and-F 1 is the first paragraph, and the space between-F and 1 is optional.

The-C can be either 1 digits n or an interval n1-n2, or multiple digits n1,n2,n3

8.11 Sort_wc_uniq Command

Command: Sort

Sort for sorting

Syntax: sort [-t delimiter] [-KN1,N2] [-nru] Here's N1 < N2

-T delimiter: function with the-D one meaning of cut

-N: Sorting with pure numbers

-R: Reverse Sort

-U: To repeat

-KN1,N2: Sorted by N1 interval to N2 interval, can only write-kn1, sort N1 field

If sort does not have any options, then the first character is backward, then the ASCII values are compared, and finally they are output in ascending order.

-T followed by a delimiter,-K followed by a number, a string that is sorted on the first range, and-n indicates the use of a purely numeric sort

-k3,5 represents a string sort from 3rd to 5th,-R for reverse ordering

Command: WC

The number of rows, characters, and words used to count the document, and the commonly used options are:

-L: Count rows

-M: Statistics of characters

-W: Number of statistical words

WC does not follow any options, directly with the document, it will be the number of rows, words, characters in turn output.

Command: Uniq

To repeat the line, the most common option for Amin is only one:

-C: Count the number of repeated rows and write the number of lines in front

Write the following content into Testb.txt, save.

The premise of using Uniq is to sort the files first, otherwise it doesn't work.

8.12 tee_tr_split Command

Command: Tee

followed by the file name, similar to the redirect ">", but the specific weighting is a feature that is also displayed on the screen while writing the file to the file that follows it.

Tee is often used after the pipe symbol "|".

Command: TR

Substitution characters, commonly used to handle special symbols appearing in a document, such as ^m symbols appearing in a DOS document. There are two common options:

-D: Delete a character, followed by the character you want to delete

-S: Remove repeated characters

The most common is to capitalize the lowercase: tr ' [A-z] ' [A-z] '

Of course, replacing a character is also possible.

However, the substitution, deletion and repetition are all aimed at one character and have some limitations. If it's no longer useful for a string, it is recommended that you simply understand the TR, and there are many more tools that you can implement for string manipulation.

Command: Split

Cutting documents, common options:

-B: Divide the document by size in bytes

If split does not specify a target file name, it will be Xaa xab ... Such a filename to access the cut file. Of course we can also specify the target file name:

-L: Split document by number of rows

8.13 Shell Special Symbol

Special symbols (top):

1.$ In addition to the identifiers used in front of variables, there is a magical use that is combined with '! '.

'!$ ' represents the last variable in the previous hit (in short, the last thing that appears in the previous command) For example, the top command is finally Testb.txt, so entering!$ under the current command represents Testb.txt.

2.; : Semicolon. Usually we are in a row to hit a command, and then enter the run, so you want to run two or two more commands in a row? You need to add a ";" between the commands.

3.~ : User's home directory, if Root is/root, ordinary user is/home/username

4.& : If you want to put a command in the background, you need to add this symbol. This is typically used when the command runs for a very long time.

5.>, >>, 2>, 2>> in front of the over-directional symbol > and >> the meaning of substitution and addition, and then there are two symbols is here 2> and 2>> Indicate error redirection and error append redirect respectively, when we run a command error, the error message will be output to the current screen, if you want to redirect to a text, you need to use 2> or 2>>

6.[] The middle bracket, which is a combination of characters that represents either of the intermediate characters.

7.&& and | |

A semicolon has just been mentioned above for the delimiter between multiple commands. There are also two special symbols that can be used in the middle of multiple commands, that is, "&&" and "| |", which are listed below in a few cases:

    1. Command1; Command2

    2. Command1 && Command2

    3. Command1 | | Command2

When using ";", Command2 will be executed regardless of whether Command1 is executed successfully;

When using "&&", only if the Command1 is executed successfully, Command2 will execute, otherwise command2 not execute;

When using "| |", the Command1 execution succeeds Command2 not execute, otherwise go to execute Command2, in short Command1 and Command2 always have a command to execute.

Before doing the experiment, we want to remove all the test*, but the deletion, but the prompt said that the authority is not enough, the following is the process of eliminating the problem:

Next, by doing experiments to explain the "&&" and "| |" The role of the two special symbols:


8.10-8.13 Shell Special Symbol

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.