Linux20180503 six-week fifth session (May 3) awk extension

Source: Internet
Author: User

Six week fifth session (May 3)
Review
Extended
Using external shell variables in awk http://ask.apelearn.com/question/199

In contrast, awk is more like a simple programming language


A=44echo "ABCD" | Awk-v get_a= $A ' {print get_a} '
Description: The-v option is used to define the parameter, which means that the value of variable A is given to get_a.
How many variables need to be assigned, and how many-V options are required. Equivalent to: Applied to the script:



awk merges a file http://ask.apelearn.com/question/493
I have the need to merge two files with the same row in the first column. For example, there are two files with the following contents:
Cat 1.txt
1 AA
2 BB
3 ee
4 SS

Cat 2.txt
1 AB
2 CD
3 AD
4 BD
5 de

The result of the merge is:

1 AB AA
2 CD BB
3 ad EE
4 BD SS
5 de

the commands implemented are:
awk ' Nr==fnr{a[$1]=$2}nr>fnr{print $0,a[$1]} ' 1.txt 2.txt

This involves

Explanation: NR represents the number of rows read, FNR indicates the current number of rows read
so in fact, nr==fnr means reading 2.txt. The same nr>fnr means when reading 1.txt
array A is actually the equivalent of a mapConcatenate a file multiple lines into a line http://ask.apelearn.com/question/266

The use of Gsub functions in awk http://ask.apelearn.com/question/200

awk intercepts specifying multiple fields as one row http://ask.apelearn.com/question/224

Filter two or more keywords http://ask.apelearn.com/question/198

Generate the following structure file with awk http://ask.apelearn.com/question/5494

awk Prints single quotation marks with print http://ask.apelearn.com/question/1738

Merge two files http://ask.apelearn.com/question/945

Awk's Reference tutorial http://www.cnblogs.com/emanlee/p/3327576.html


Linux20180503 six-week fifth session (May 3) awk extension

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.