implementation of awk

https://blog.csdn.net/fengyuanye/article/details/82858863

 

awk implementation of three forms:

1. Direct command line is performed,
        the syntax of the form: awk [option] 'awk statement' text files to be processed, as shown in examples:

 

2. awk script file to perform
need to add the -f option; syntax is: awk -f awk script file to be processed, as shown in specific examples:

 

3. in the form of a shell script to execute
        when executed in the form of a shell script, the first line of #! / Bin / bash to be converted to a #! / Bin / awk (awk where the path), and later need to add the -f option, otherwise it will error. FIG concrete examples:

 

The results shown in Figure:

 

document content:

 

Another example:

 

awk variable without defined, or direct assignment may operate.

 

 

When the operation of the variable value, such as + 1, -1, + and other operations, the value is the value, and the default value is 0.

If the variable string operation, the default value is a string.

Similar awk array k, v mapping relationship may be digital as subscripts index may be an index string representing a subscript, or even multi-dimensional string index.

In the form of execution of the shell script variable, directly by two quotes, "" connected string variables or other variables can be directly string concatenation, such as:

 

Figure, a [1] is a string variable reg defined before, may be connected to a string as an index of the array, the array values ​​are a string; may be carried out continuously by adding a value corresponding to its next index mark. Array variable which can take the value "" splicing, instead of the variable as a shell script, with the required value by $ {string variable.

String array traversal of the index table:

 

For non-numerical subscript, generally array traversal by this method.

Guess you like

Origin www.cnblogs.com/keystone/p/11274255.html
awk