How does awk reference external variables?

Source: Internet
Author: User
Awk uses the following methods to reference external variables to call variables: www.2cto. com1.awk & amp; #39; {printa, B} & amp; #39; a111b222yourfile note: The variable must be placed before the file name; otherwise, it cannot be called. example: awk & amp; #39; {p... awk uses the following methods to reference external variables to call variables: www.2cto.com 1. awk '{print a, B} 'a = 111 B = 222 yourfile note that the variable location must be before the file name, otherwise it cannot be called. for example: awk '{print a, B} 'a = 111 file1 B = 222 file2file1 cannot call B = 222. also, variable cannot be called in BEGIN. it can be solved using the second method described later. www.2cto.com 2. awk-v a = 111-v B = 2 22 '{print a, B}' yourfile note: add a-v to each variable for transmission. 3. awk '{print "'" $ LOGNAME "'}' yourfile if you want to call environment variable, use the above method: (I add spaces to make it easy for everyone to understand) "'" $ LOGNAME "'" instance :#! /Bin/bash # This function lists the names of files whose names start with a date and are earlier than a certain date. It can be used to delete filtering curdate = 20110715 Filename = 'ls-l | awk-v cdate = $ curdate 'NR! = 1 & $8

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.