Examples of using Awk in English and their translations into Chinese
{-}
-
Political
-
Ecclesiastic
-
Programming
The GNU awk programming language.
As mentioned in the preface, this book describes POSIX awk;
Awk- a pattern scanning and processing language".
Both of these examples illustrate that awk is usually input-driven.
To write an awk script, you must become familiar with the rules of the game.
Remember that we already walked through how touse next statement in Part 6 of this Awk series.
It might be useful if your awk's printf does unbiased rounding.
Awk is one of those languages that, once learned, will become a key part of your strategic coding arsenal.
Initially, using sed and awk will seem like the long way to accomplish a task.
Awk allows you to use the structure of a text file in writing the procedures for putting things in and taking things out.
If you would like, you can create an awk program that will output data totally unrelated to the input data.
The awk program(name from the initials of its authors- Aho, Weinberger and Kernighan) is a tool originally for formatting reports.
We set FS(the field separator) to"\t+", which tells awk that the fields will be separated by one or more tabs.
Because awk is essentially designed as a string-processing language, a lot of its power derives from these functions.
However, there are many programming situations where youmay need to execute initialization code before awk begins processing the text from the input file.
When you run awk, you specify an awk program that tells awk what to do.
When awk encounters the first assignment, myarray is created and the element myarray[1] is set to"jim".
The idea was to hand this data to an awk script that would automatically add up all the amounts and tell me my balance.
When awk processes the print $1 command, it will print out the first field that appears on each line in the input file.
Next, we add piping to execute the awk command, which displays the 9th column from the filtered output from the grep command.
Once awk knows how the input is formatted, it can do all the parsing work for us, and the rest of the script is simple.
When you run awk, you specify an awk program that tells awk what to do.
Although awk was designed as a programmable editor, users found that awk scripts could do a wide range of other tasks as well.
When you invoke the awk program, it reads the script that you supply, checking the syntax of your instructions.
The condition is an Awk expression and actions are lines of Awk commands executed when the condition is true.
By creating a variable, AWK, to hold the name of the awk program you make it easier for other users of your makefile.
Redirections in awk are written just like redirections in shell commands, except that they are written inside the awk program.