Grep & awk

Source: Internet
Author: User

====================================
Grep [Option] basic regular expression [file]

1. Option
-C: only counts matching rows.
-I is case insensitive (single character)
-H does not display file names (when multiple files are used)
-L only output file names (when multiple files are used)
-N: display matching rows and row numbers
-S does not display error messages
-V: Display All rows that do not contain matched text

2. query multiple files
Grep "sort" *. Doc
Grep "sort "*

3. Use a regular expression. It is best to enclose it in single quotation marks ('').
Grep '[ss] ORT' *. Doc

4. You can use the pipeline command. | the output on the left is the input on the right.
Grep '[ss] EPT 'data. f | grep 483

Awk
====================================
There are three methods to call awk
1. Command Line
Awk [-F field-separator] 'commands' input-file (s)
// [-F domain separator] is optional, because awk uses space as the default domain separator. If there is space in the field, you do not need to specify this option. However, for example, in the passwd file, the field separator is:-F must be specified for all fields. For example:
// Awk-F: 'commands' input-File

2. Write to the shell file
3. Write a separate file and call:
Awk-F awk-script-file input-files (s)
//-F indicates the awk script in the awk-script-file.
4. actions must be included in {}

--------------------------------
1. $1 $2... $ n indicates each domain, and $0 indicates all domains
2. Regular Expressions are included with //:/Regular Expressions/
3 .~ Match !~ Mismatch
4. If () is followed by (), you can use <= >>=! = & |
//
// Awk '{if ($4 = "yellow" & $2 ~ /[Gg] reen/)} 'filename'
//
---------------------------------

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.