Shell Common Command Summary (iii)

Source: Internet
Author: User

1.1. usage of the Cut command in the shell

The first usage is similar to awk, as shown in awk below :

Cat/etc/passwd|awk-f: ' {print $1,$5} '

Cut-d: The colon after-F 1,5/etc/passwd/-d indicates the delimiter between the fields, and-f indicates which fields after the de-delimiter

You can also use the cut command to cut partial characters with a scalar number of characters, which is implemented with the- C option and cannot coexist with the- d option.

Cut-c 1-4/etc/passwd # takes the first 1-4 characters of each line

1.2. Return line break

line break in Windows system is CRLF, English is carriage-return(enter \ r) Line-free (line break \ n ). So, when a shell script written by the Windows system runs on Linux , a transformation is required. Otherwise it will report a grammatical error "syntax error near unexpected token"

1.3. double quotes after Echo

Without double quotes, special variables are escaped with special symbols in the output variable, such as:

(1) for I in 2 \*;d o echo $i;d one;

(2) for I in 2 \*;d o echo "$i";d one;

The first statement does not display an asterisk, which represents all files in the current directory. Instead, you should use the second usage.

Shell Common Command Summary (iii)

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.