Awk uses shell parameter variables

Source: Internet
Author: User
Awk processes a line of text. when you need to determine whether the current processing line meets the specific conditions, you need to input parameters from the shell, and then put them in the awk script command for processing. For example, if awk reads the shell location parameter $1 directly in the awk command, it will conflict with the first field $1 in each line... "/> <scripttype =" text/javascript "src =" htt awk is a line of processing text. when you need to determine whether the current processing line meets specific conditions, you need to input parameters from the shell and put them in the awk script command for processing. For example, if awk reads the shell location parameter $1 directly in the awk command, it will conflict with the first field $1 in each line, and special processing is required. For example, if the iet.txt file is in the following format, you need to extract the first field or the second field is aa bb cc dd ee ff gg dd... the script is as follows and saved as tiqu. sh #! /Bin/bash sed '/^ $/d' iet.txt | awk '{if (NF> 3 & ($1 = "' $ 1'" | $2 = = "'$1 '")) {print $1 "," $2 "," $6} 'execution method: bash tiqu. sh AA output result: aa bb ff description: sed '/^ $/d' iet.txt removes empty lines in the text, awk then judges that if the current row has more than three fields and the conditions are met, it will output the values of columns 1, 2, and 6, and isolates shell variables with single quotes, double quotation marks are used to enclose both sides of the shell variable. Awk tutorial common awk command format awk-F separator 'In in {Initialization} {loop execution part} END {END processing} 'file Separator, BEGIN, END part can be omitted, the default delimiter is the space simplified awk format awk '{cyclic execution command}' file common awk commands: awk column summation awk 'In in {total = 0} {total + = $1} END {print total} 'to be improved ..., if you have any good commands, you can leave a message to me.

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.