Shell Scripting and Destiny

Source: Internet
Author: User

    1. variables, functions, definitions and references, which are expressed in many ways, I choose the following:

Variable name = ' destined ' #变量定义

$ variable Name #变量的引用


Function name ()

{

Destined 1;

Destined 2;

.....

} #函数的定义

Function name #函数的引用

For example, my first article it

User_add ()

{

ID smbmin &>/dev/null; #smbmin是已经存在的用户

while (($?==0))

Do

Read-p "Please input user name:" USER_NAME;

ID $user _name &>/dev/null;

Done

Useradd $user _name-g smbkefu-s/sbin/nologing;

Smbpasswd-a $user _name;

echo "$user _name is ok!"

} #定义user_add函数

User_add #引用user_add函数

2. Common destiny in scripts

Sort is mainly used for sorting, it has a lot of options, I only list the commonly used

-N: Sort by number

-R: Reverse Sort

-U: Show only non-repeating

And one is to sort by a column.

Sort-t ' delimiter '-K ' column number '


Uniq is mainly used to remove heavy and statistical duplicates of rows

-I: Ignore case

-C: Count the number of repetitions of non-peers

-U: only display unique rows


awk processes a file in a row, primarily to intercept a piece of information in a file

The basic expression is: awk-f ' delimiter ' condition {print positional parameter ' output statement ' positional parameter} '

The whole line,

$n as Nth field

NR is the line number

NF is the total number of rows


Sed text online Editing tool, one line of processing, mainly for the file additions and deletions to search

The basic expression is: sed-[option] "line number, line number action" file

or sed-[option] "/Condition/action" file

Among the main common options are:

-I: Directly to the contents of the file operation

-N: Show matching rows, no people will show all

Delete: Remove behavior in action D; To delete a field this is done with the s/field//g, which is the principle of turning this field into a space for deletion.

Increment: Add a new line before a line mainly with I, a line after a; If you want to add but do not break line at the beginning of the s/^/field/, the end of the line add but do not change the behavior s/$/field/; To add a field 1 before a field 2: s/Field 1/Field 1 field 2/.

Change: To change the field 1 to Field 2 is: s/Field 1/Field 2/g, the addition of G is a global substitution, otherwise only the first field of the matching row is replaced.

Check: the-n option and the p operation are used.

It is important to note that the operation of the SED = Print line number.


Cut is used to intercept a field

-d ' Specify delimiter '

-F ' extracted segment number '

-C in Characters


WC used to count

-L Statistics Total rows

-W Statistics Total characters

-M statistics Total bytes

grep is used to filter general and |

-C: Count rows

-N: Show line numbers

-E: Supports regular expressions and can also write Egrep

-V: Show mismatched rows (inverse)


Tail-n number to the bottom of a few lines

Head-n numbers take the first few lines

This is my current collation of the practical options, if there are errors please correct me, if there are better or supplement please suggest

This article is from the "innovation sharing gallop inside and out" blog, please be sure to keep this source http://10554846.blog.51cto.com/10544846/1679242

Shell Scripting and Destiny

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.