Introduction to AWK language in AIX

Source: Internet
Author: User

The AWK language in AIX introduces the basic functions of [plain] www.2cto.com awk: allows you to specify rules to browse and extract information in text or strings. Other text operations can be performed only after the awk extracts information. The complete awk script is usually used to format the information in the text. Three methods to call awk: 1. command Line Method: awk [-F field-separator] 'commands' input-file (s)-F option Optional: awk-F: 'commands' input-file 2. insert all the awk commands into a file and run the awk program. Then, use the awk command interpreter as the first line of the script to call it by typing the Script Name. 3. insert all the awk commands into a separate file and call: awk-f awk-script-file input-files (s)-f: specifies the awk script input-file (s) in the file awk-script-file: the file name browsed by awk. When an awk script calls an awk in a command, the awk script consists of various operations and modes. -F, awk reads a record or line each time, and uses the specified separator to separate the specified domain. If there is no separator, spaces are used. All awk statements consist of modes and actions, which determine when the Action Statement is triggered and trigger events. If the mode part is ignored, the action is always executed. Mode, but any conditional statement, statement, or regular expression. BEGIN: sets the count and print head before any Text Browsing action. END: used to print the total number of output files and the ending status mark after awk completes file browsing. Action, specified in {}; mostly used for printing; it can include: if, looping, and loop release structure. if no action is specified, awk will print all browsing records. Example: cat> grade.txt M. tansley 05/99 48311 Green 8 40 44 J. lulu 06/99 48317 green 9 24 26 P. bunny 02/99 48 Yello 12 35 28 J. troll 07/99 4842 Brown-3 12 26 26 L. tansley 05/99 4712 Brown-2 12 30 28 Save the data output from awk: 1.awk '{print $0}' grade.txt> wow pg wow stuname indate seqno level age gnow gmax M. tansley 05/99 48311 Green 8 40 44 J. lulu 06/99 48317 green 9 24 26 P. bunny 02/99 48 Yello 12 35 28 J. trol L 07/99 4842 Brown-3 12 26 26 L. tansley 05/99 4712 Brown-2 12 30 28 2. use the tee command, save and output the stored data to the [development]/usr/b4nx/ytcclb> awk '{print $0} 'grade.txt | tee delete_me_and_die stuname indate seqno level age gnow gmax M. tansley 05/99 48311 Green 8 40 44 J. lulu 06/99 48317 green 9 24 26 P. bunny 02/99 48 Yello 12 35 28 J. troll 07/99 4842 Brown-3 12 26 26 L. tansley 05/99 4712 Brown-2 12 30 28 [developer]/usr/b4nx/ytccl B> pg delete_me_and_die stuname indate seqno level age gnow gmax M. tansley 05/99 48311 Green 8 40 44 J. lulu 06/99 48317 green 9 24 26 P. bunny 02/99 48 Yello 12 35 28 J. troll 07/99 4842 Brown-3 12 26 26 L. tansley 05/99 4712 Brown-2 12 30 28 print all data awk '{print $0}' grade.txt M. tansley 05/99 48311 Green 8 40 44 J. lulu 06/99 48317 green 9 24 26 P. bunny 02/99 48 Yello 12 35 28 J. troll 07/99 4842 Brown-3 12 26 26 L. tansley 05/99 4712 Brown-2 12 30 28 print partition data awk '{print $1, $4}' grade.txt M. tansley Green J. lulu green P. bunny Yello J. troll Brown-3 L. tansley Brown-2 awk command error: awk '{print $1, & 4}' wow awk: Syntax error at line 1 of program <{print $1, & 4 }>> context is {print >>1 1, & <4} awk: illegal statement at line 1 of program <{print $1, & 4 }>> cause of error: Incorrect Parameter input, & 4 for $4 Printing Report header [development]/usr/b4nx/ytcclb> Wk 'in in {print "Name Belt \ n ------------" }>{ print $1 "\ t" $4} 'wow Name Belt ------------ M. tansley Green J. lulu green P. bunny Yello J. troll Brown-3 L. tansley Brown-2 print row tail error: awk 'in in {print "Name \ n --------"} {print $1} END> {"end-of-report"} 'wow awk: syntax error at line 2 of program <BEGIN {print "Name \ n...> context is BEGIN {print "Name \ n --------" }{ print $1} END >>< <awk: bailing Out at line 2 of program <BEGIN {print "Name \ n...> cause: line feed. Awk 'in in {print "Name \ n --------"} {print $1} end {"end-of-report"} 'wow Name -------- M. tansley J. lulu P. bunny J. troll L. tansley awk error, search 1. make sure that the entire awk command is enclosed in single quotes; 2. make sure that all quotation marks in the command appear in pairs; 3. make sure that the Action Statement is enclosed in curly brackets and the Condition Statement is enclosed in parentheses;

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.