Basic knowledge of Linux learning

Source: Internet
Author: User

Common commands:

1.awk:http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html

Awk is a powerful text analysis tool, with the search for grep and the editing of SED, which is especially powerful when it comes to analyzing data and generating reports. To put it simply, awk reads the file line-by-row, using spaces as the default delimiter to slice each row, and then perform various analytical processing of the cut.


AWK has 3 different versions: AWK, Nawk, and gawk, which are not specifically described, generally referred to as the GNU version of Awk Gawk,gawk

How to use:

awk ' {pattern + action} ' {filenames}

Three ways to invoke awk:

A. Command line

B.shell Script

C. Insert all awk commands into a separate file and then call the

Mainly on the command line mode:

awk [-F Field-separator] 'commands' input-file(s)

Example:

Use together with other commands

Obtaining an IP address from a command

2.grep command: http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856896.html

grep (Global search Regular expression (RE) and print out of the line, full search of regular expressions and print out rows) is a powerful text search tool that uses regular expressions to search for text. and print out the matching lines.

The grep family of Unix includes grep, Egrep, and Fgrep. Egrep and Fgrep commands are only a small difference from grep. Egrep is the extension of grep, which supports more re metacharacters, and fgrep is fixed grep or fast grep, which regards all the letters as words, that is, the metacharacters in the regular expression represents the literal meaning back to itself, no longer special. Linux uses the GNU version of grep. It is more powerful and can use the Egrep and FGREP functions with the-G,-e,-f command line options.

Usage of grep:

 grep [-ACINV] [--color=auto]  " search string  ' 

Sed is an online editor that processes a single line of content at a time. When processing, the currently processed rows are stored in a temporary buffer called pattern space, followed by the SED command to process the contents of the buffer, and after processing is done, the contents of the buffer are sent to the screen.

Then the next line is processed, so it repeats until the end of the file. The file content does not change unless you use redirection to store the output. SED is mainly used to automatically edit one or more files, to simplify the repeated operation of the file, to write the conversion program and so on.

[email protected] ~]# sed [-NEFR][Action] Options and Parameters:-N: Use Quiet (silent) mode. In generalIn the use of SED, all data from STDIN is generally listed on the terminal. But if you add-n parameter, only the line (or action) that is specially processed by SED is listed. -e: Directly in command-line modeSedThe action editor;-F: DirectlyThe action of SED is written in a file, and-f filename can be run in filenameSedAction;-R:sed The action supports the syntax of the extended formal notation. (The default is the basic formal notation French)-i: Directly modifies the contents of the read file, not the output to the terminal. Action Description: [N1[,n2]]functionn1, N2: Not necessarily exist, generally represents "select the number of rows to act on" , for example, if my action is required in 10 to 20 10,20 Function:a: New, A can be followed by a string, and these strings will appear on a new line (the current next line) ~c: Replace, C can be followed by strings, these strings can replace the line between N1,N2! D: Delete, because it is deleted, so d usually do not take any knock; I: Insert, I can be followed by a string, and these strings will appear on a new line (the current line); P: Print, that is, print out a selected data. Normally p will be sed-n run ~s: Replace, can be directly replaced by work! Usually this s action can be paired with formal notation! For example 1,20s/old/new/g! 

Delete Line 2nd

NL sed.txt|sed ' 2d ';

Delete Line 3rd to last row

NL sed.txt|sed ' 3, $d ';

Add BBB after the first line

NL sed.txt|sed ' 2a BBB ';

If the first line of money

NL sed.txt|sed ' 2i BBB ';

Add more than 2 lines

NL Sed.txt | Sed ' 1a Drink tea or ... \ Drink beer? '

Note: Each line is added with \ to

Replace:

NL Sed.txt | sed ' 2,5c hello sed '

Show only 5-7 rows

nl/etc/passwd | sed-n '5,7p'

Searches for/etc/passwd with the root keyword, and if Root finds it, it outputs a matching line in addition to all rows.

Only the rows containing the template will be printed when using-n

Delete/etc/passwd all rows containing root, other rows output

Basic knowledge of Linux learning

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.