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