Write an awk script in the shell script to extract data. Note the format. Use shell variables in the awk, convert the numeric strings in the awk to numbers, and compare the strings in the awk.

Source: Internet
Author: User

In awk programming, do not forget that awk processes regular expressions. There are many internal functions, especially string processing functions. Calling these functions can reduce the workload.

1. Format

// Note \ There cannot be spaces behind the end, and the start position "'" and end position "'" cannot be forgotten.

Awk-F '&'\

'In in {

// Awk begin part

}

{

// The execution part of the awk. To exit during the processing, use exit (value); equivalent to break in for in C Language

}

End

{

// Awk end part

} '$ {Old_filename} >$ {new_filename} // old_filename is the file name to be processed

 

2. variable reference

In the awk section, use the shell variable awk_value_name = "'$ {shell_value_name }'";

For example:

// Where blockid is the awk variable, and blockid is the shell variable. 3. How to convert a string number to a number in awk: blockid = "1245"; When blockid is required to be a number, blockid = blockid + 0; 4. The string in awk is equal. Use = to judge.

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.