Home > php教程 > PHP开发 > Detailed explanation of AWK commands (complete collection)

Detailed explanation of AWK commands (complete collection)

高洛峰
Release: 2016-12-15 10:41:24
Original
1752 people have browsed it

What is awk?

You may be familiar with UNIX, but you may be unfamiliar with awk. This is not surprising at all. Indeed, compared with its excellent functions, awk is far from the popularity it deserves. What is awk? Unlike most other UNIX commands, it is impossible to know the function of awk from its name: it is neither an English word with independent meaning, nor an abbreviation of several related words. In fact, awk is the abbreviation of three people's names: Aho, (Peter) Weinberg and (Brain) Kernighan. It was these three people who created awk---an excellent style scanning and processing tool.

What are the functions of AWK? Much like sed and grep, awk is a pattern scanning and processing tool. But its function is much stronger than sed and grep. Awk provides extremely powerful functions: it can complete almost all the work that grep and sed can do. At the same time, it can also perform style loading, flow control, mathematical operators, process control statements and even built-in variables and functions. . It has almost all the beautiful features that a complete language should have. In fact, awk does have its own language: the awk programming language. The three creators of awk have officially defined it as: style scanning and processing language.

Why use awk?

Even so, you may still ask, why should I use awk?

The first reason to use awk is that text-based style scanning and processing is what we often do, and awk does It works somewhat like a database, but unlike a database, it deals with text files. These files have no special storage format, and ordinary people can edit, read, understand and process them. Database files often have special storage formats, which makes it necessary to use a database processing program to process them. Since we often encounter this kind of database-like processing work, we should find simple and easy ways to deal with them. UNIX has many tools in this area, such as sed, grep, sort, find, etc., among which awk is A very excellent one.

The second reason for using awk is that awk is a simple tool. Of course, this is relative to its powerful functions. Indeed, UNIX has many excellent tools. For example, UNIX's natural development tool C language and its continuation C++ are very excellent. But compared to them, awk is much more convenient and simpler to complete the same function. This is first of all because awk provides solutions to meet a variety of needs: from the awk command line to solve simple problems to the complex and exquisite awk programming language. The advantage of this is that you do not have to use complicated methods to solve otherwise very complex problems. Simple question. For example, you can use a command line to solve simple problems, but C cannot. Even for a simple program, C language must go through the entire process of writing and compiling. Secondly, awk itself is interpreted and executed, which means that the awk program does not have to go through the compilation process. At the same time, this also makes it fit well with the shell script program. Finally, awk itself is simpler than the C language. Although awk absorbs many excellent elements of the C language, being familiar with the C language will be of great help in learning awk, but awk itself does not need to use the C language - a powerful but necessary Development tools that take a lot of time to learn to master.

The third reason to use awk is that awk is an easily available tool. Unlike the C and C++ languages, awk has only one file (/bin/awk), and almost every version of UNIX provides its own version of awk. You don't have to worry about how to get awk. But this is not the case with the C language. Although the C language is a natural development tool for UNIX, this development tool is released separately. In other words, you must pay separately for your UNIX version of the C language development tool (except for those who use the D version of course) ), obtain and install it before you can use it.

Based on the above reasons, coupled with the powerful functions of awk, we have reason to say that if you want to deal with work related to text style scanning, awk should be your first choice. There is a general principle to follow here: if you have difficulty using ordinary shell tools or shell scripts, try awk. If awk still does not solve the problem, then use C language. If C language still fails, then move to C++.

How to call awk

As mentioned before, awk provides different solutions to meet various needs. They are:

1. Awk command line. You can use awk like ordinary UNIX commands. In the command line You can also use the awk programming language. Although awk supports multi-line entry, it is a headache to enter a long command line and ensure that it is correct. Therefore, this method is generally only used to solve the problem. Simple question. Of course, you can also reference the awk command line or even the awk program script in the shell script program.

2. Use the -f option to call the awk program. Awk allows you to write an awk program to a text file, and then call and execute this program using the -f option on the awk command line. The specific method will be discussed later in the awk syntax.

3. Use the command interpreter to call the awk program: Using the command interpreter function supported by UNIX, we can write an awk program into a text file, and then add:
to its first line#!/bin/awk -f
And give this text file execution permission. After doing this, you can call and execute this awk program from the command line in a manner similar to the following.

$awk script text name file to be processed

awk syntax:

Like other UNIX commands, awk has its own syntax:

awk [ -F re] [parameter...] ['prog'] [ -f progfile][in_file...]

Parameter description:

-F re: Allow awk to change its field separator.

parameter: This parameter helps assign values ​​to different variables.

'prog': awk program statement segment. This statement segment must be enclosed in single extension symbols: ' and ' to prevent it from being interpreted by the shell. The standard form of this program statement segment is:

'pattern {action}'

The pattern parameter can be any one of the egrep regular expressions, which can be formed using the syntax /re/ plus some style matching techniques. Similar to sed, you can also use "," to separate two styles to select a range. For the details of matching, you can refer to the appendix. If you still don't understand, find a UNIX book to learn grep and sed (I mastered the matching technology when I was studying ed). The action parameter is always surrounded by curly brackets. It consists of a system awk statement, separated by ";". awk interprets them and performs its operations on records matching the pattern given by pattern. Similar to the shell, you can also use "#" as the comment character, which makes the content from "#" to the end of the line a comment, and they will be ignored when interpreting and executing. You can omit either pattern or action, but not both at the same time. When pattern is omitted, there is no style matching, which means that all rows (records) are operated. When action is omitted, the default operation is performed - displayed on the standard output. .

-f progfile: Allows awk to call and execute the program file specified by progfile. progfile is a text file, and it must conform to the syntax of awk.

in_file: awk input file, awk allows processing of multiple input files. It's worth noting that awk does not modify input files. If no input file is specified, awk accepts standard input and displays the results on standard output. awk supports input and output redirection.

awk’s records, fields and built-in variables:

As mentioned before, the processing work of awk is similar to the processing method of database. One of the similarities is that awk supports the processing of records and fields, among which the processing of fields The processing cannot be achieved by grep and sed, which is one of the reasons why awk is better than the two. In awk, by default, a line in a text file is always regarded as a record, and a certain part of a line is regarded as a field in the record. In order to operate these different fields, awk borrows the shell's method and uses $1, $2, $3... to sequentially represent different fields in the row (record). Specifically, awk uses $0 to represent the entire row (record). Different fields are separated by characters called delimiters. The system default delimiter is space. Awk allows you to change this separator using the -F re form on the command line. In fact, awk uses a built-in variable FS to remember this separator. There are several such built-in variables in awk, such as the record separator variable RS, the number of records currently working NR, etc. The appendix at the end of this article lists all built-in variables. These built-in variables can be referenced or modified in the awk program. For example, you can use the NR variable to specify the working range in pattern matching, or you can modify the record separator RS to use a special character instead of a newline character as the record separator.

Example: Display the first field, the third field and the seventh field separated by the character % in the seventh line to the fifteenth line of the text file myfile:

awk -F % 'NR==7,NR==15 {printf $1 $3 $7}'

awk's built-in functions

One of the reasons why awk has become an excellent programming language is that it absorbs many advantages of some excellent programming languages ​​(such as C). One of these advantages is the use of built-in functions. Awk defines and supports a series of built-in functions. Due to the use of these functions, the functions provided by awk are more complete and powerful. For example, awk uses a series of built-in string processing functions. Functions (these functions look similar to the string processing functions of the C language, and their usage is similar to the functions in the C language). It is precisely because of the use of these built-in functions that awk's function of processing strings is more powerful. The appendix at the end of this article lists the built-in functions provided by general awk. These built-in functions may be somewhat different from your version of awk. Therefore, before using them, it is best to refer to the online help in your system.

As an example of a built-in function, we will introduce here the printf function of awk, which makes the output of awk consistent with the C language. In fact, many reference forms in awk are borrowed from the C language. If you are familiar with C language, you may remember the printf function. The powerful format output function it provides has brought us a lot of convenience. Fortunately, we met it again in awk. Printf in awk is almost exactly the same as in C language. If you are familiar with C language, you can use printf in awk according to the pattern of C language. Therefore, here, we only give an example. If you are not familiar with it, please find an introductory book on C language and read it.

Example: Display the line number and field 3 in the file myfile:

$awk '{printf"%03d%s",NR,$1}' myfile

Use awk on the command line

In order, we should Let’s explain the content of awk programming, but before explaining, we will use some examples to review the previous knowledge. These examples are all used in the command line, so that we can know how to use awk in the command line. of convenience. The reason for this is on the one hand to pave the way for the following content, and on the other hand to introduce some methods to solve simple problems. There is no need for us to use complicated methods to solve simple problems - since awk provides a relatively simple In terms of method.

Example: Display all lines of the text file mydoc that match (contain) the string "sun".

$awk '/sun/{print}' mydoc

Since displaying the entire record (full line) is the default action of awk, the action item can be omitted.

$awk '/sun/' mydoc

Example: The following is a more complex matching example:

$awk '/[Ss]un/,/[Mm]oon/ {print}' myfile

it will display the lines between the first line matching Sun or sun and the first line matching Moon or moon to standard output.

Example: The following example shows the use of the built-in variable and the built-in function length():

$awk 'length($0)>80 {print NR}' myfile

This command line will display all the text in myfile that exceeds 80 A line number of characters. Here, $0 is used to represent the entire record (line). At the same time, the built-in variable NR does not use the identifier '$'.

Example: As a more practical example, we assume that we want to perform security checks on users in UNIX by examining the passwd file under /etc and checking whether the passwd field (second field) is "*". If it is not "*", it means that the user has not set a password, and these user names (first field) are displayed. We can achieve this with the following statement:

#awk -F: '$2=="" {printf("%s no password!",$1' /etc/passwd

In this example, the field delimiter of the passwd file is ":", therefore, -F: must be used to change the default field separator. This example also involves the use of the built-in function printf.

awk variables

Like other programming languages, awk allows the program to be used. Setting variables in the language, in fact, providing the function of variables is an essential requirement of a programming language. I have never seen a programming language that does not provide variables.

awk provides two types of variables, one is the built-in variable of awk. , we have already mentioned this before, and it is important to point out that, unlike other variables mentioned later, there is no need to use the identifier "$" when referencing built-in variables in an awk program (recall the use of NR mentioned earlier ). Another type of variable provided by awk is a custom variable. awk allows users to define and call their own variables in awk program statements. Of course, such variables cannot be the same as built-in variables and other awk reserved words, and can be referenced in awk. Variables must be preceded by the identifier "$". Unlike the C language, variables do not need to be initialized in awk. awk determines its specific data type based on the form and context of its first appearance in awk. When the variable type is undefined, awk defaults to the string type. Here is a trick: If you want your awk program to know the explicit type of the variable you are using, you should assign it an initial value in the program. In the following examples, we will use this technique.

Operation and judgment:

As one of the characteristics of a programming language, awk supports a variety of operations, which are similar to those provided by the C language. Basically the same: such as +, -, *, /, %, etc. At the same time, awk also supports functions like ++, --, +=, -=, =+, =- in C language, which is very familiar to you. It brings great convenience for users of C language to write awk programs. As an extension of computing functions, awk also provides a series of built-in computing functions (such as log, sqr, cos, sin, etc.) and some functions. Functions that operate on strings (such as length, substr, etc.). The references of these functions greatly improve the operation function of awk.As part of the conditional transfer instructions, relational judgment is a function that every programming language has, and awk is no exception. A variety of tests are allowed in awk, such as the commonly used == (equal),! = (not equal to), > (greater than), < (less than), >= (greater than or equal to), >= (less than or equal to), etc. At the same time, as a style matching, ~ (matches in) is also provided and! ~ (does not match) judgment.

As an extension to testing, awk also supports multiple judgments using logical operators:! (not), && (and), || (or) and brackets (), which greatly enhances the functionality of awk. The appendix to this article lists the operations, judgments, and operator priorities allowed by awk.

Awk's flow control

Flow control statements are an indispensable part of any programming language. Any good language has some statements that perform flow control. The complete flow control statements provided by awk are similar to C language, which brings great convenience to our programming.

1. BEGIN and END:

There are two special expressions in awk, BEGIN and END, both of which can be used in pattern (refer to the previous awk syntax). The function of providing BEGIN and END is to give the program Initial state and perform some finishing work after the program ends. Any operations listed after BEGIN (within {}) will be executed before awk starts scanning the input, while operations listed after END will be executed after the entire input has been scanned. Therefore, BEGIN is usually used to display variables and preset (initialized) variables, and END is used to output the final result.

Example: Accumulated sales amount in sales file }
>{print $3;total=total+$3;}
>END {printf "Total sales amount: %.2f",total}' sx
(Note: > is the second prompt provided by the shell, such as To break the line in the shell program awk statement and awk language, you need to add a backslash at the end of the line)

Here, BEGIN presets the internal variable FS (field separator) and the custom variable total, and displays it before scanning Output line header. And END prints out the total after the scan is completed.

2. Process control statement
awk provides a complete process control statement, its usage is similar to that of C language. Let’s explain them one by one below:

2.1, if...else statement:

Format:
if (expression)
Statement 1
else
Statement 2

In the format, "Statement 1" can be multiple statements, If you want to facilitate awk's judgment and your own reading, you'd better enclose multiple statements with {}. The awk branch structure allows nesting, and its format is:

if (expression 1)
{if (expression 2)
statement 1
else
statement 2
}
statement 3
else {if (expression 3)
Statement 4
else
Statement 5
}
Statement 6

Of course you may not use such a complex branching structure during actual operation, this is just to give its style.

2.2, while statement

format is:

while (expression)
statement

2.3. do-while statement

format is:

do
{
statement
}while (conditional judgment statement)

2.4. The for statement

The format is:

for (initial expression; termination condition; step expression)
{statement}

The break and continue statements are allowed in the while, do-while and for statements of awk. Control the flow of the process and also allow the use of statements such as exit to exit. break interrupts the currently executing loop and jumps outside the loop to execute the next statement. continue jumps from the current position to the beginning of the loop for execution. There are two situations for the execution of exit: When the exit statement is not in END, the exit command in any operation behaves as if it has reached the end of the file, all modes or operation execution will stop, and the operations in END mode are executed. An exit appearing in END will cause the program to terminate.

Example: For custom functions in

awk

defining and calling the user’s own functions is a function that almost every high-level language has, and awk is no exception, but the original awk does not provide function functions, only in Functions can only be added in nawk or newer awk versions.

The use of functions includes two parts: function definition and function calling. The function definition includes the code to be executed (the function itself) and the temporary call passed to the function from the main program code.

awk function is defined as follows:

function function name (parameter list) {
function body
}

It is allowed to omit function to func in gawk, but other versions of awk do not allow it. The function name must be a legal identifier. No parameters may be provided in the parameter list (but a pair of brackets after the function name is still indispensable when calling the function), or one or more parameters may be provided. Similar to C language, awk parameters are also passed by value.

Calling functions in awk is relatively simple. The method is similar to C language, but awk is more flexible than C language. It does not perform parameter validity checking. In other words, when you call a function, you can list more or fewer parameters than the function expects (specified in the function definition). The extra parameters will be ignored by awk, and the insufficient parameters will be set by awk as defaults. Value 0 or an empty string, depending on how the parameter is used.

The awk function has two return methods: implicit return and explicit return. When awk executes to the end of the function, it automatically returns to the calling program, which is why the function returns implicitly. If you need to exit a function before it ends, you can explicitly use a return statement to exit early. The method is to use a statement in the format of return return value in the function.

Example: The following example demonstrates the use of the function. In this example, a function named print_header is defined, which calls two parameters, FileName and PageNum. The FileName parameter is passed to the file name currently used by the function, and the PageNum parameter is the page number of the current page. The function of this function is to print (display) the file name of the current file and the page number of the current page. After completing this function, this function will return the page number of the next page.

nawk
>'BEGIN{pageno=1;file=FILENAME
>pageno=print_header(file, pageno); #Call function print_header
>printf("The current page number is: %d",pageno) ;
>}

>#Define function print_header
>function print_header(FileName,PageNum){
>printf("%s %d",FileName,PageNum); >PageNum++;return PageNUm;
> ;}
>}' myfile

Executing this program will display the following content:

myfile 1
The current page number is: 2

awk advanced input and output

1. Read the next record:

awk The next statement causes awk to read the next record and complete the pattern matching, and then immediately perform the corresponding operation. Typically it executes the code in the operation using a matching pattern. next causes any additional matching patterns for this record to be ignored.

2. Simply read a record

awk’s getline statement is used to simply read a record. Getline is especially useful if the user has a data record that resembles two physical records. It completes the separation of general fields (set field variables $0 FNR NF NR). Returns 1 on success, 0 on failure (end of file reached). If you need to simply read a file, you can write the following code:

Example: Example of use of getline

{while(getline==1)
{
#process the inputted fields
}
}

can also be used getline stores input data in a field instead of processing general fields using getline variables. When using this method, NF is set to 0 and FNR and NR are incremented.

Users can also use getline<"filename" to input data from a given file instead of inputting data from the content listed on the command line. At this point, getline will complete the general field separation (setting field variables $0 and NF). If the file does not exist, it returns -1 for success, 1 for failure, and 0 for failure. The user can read data from a given file into a variable, or replace filename with stdin (standard input device) or a variable containing the file name. It is worth noting that FNR and NR are not modified when using this method.

Another way to use the getline statement is to accept input from a UNIX command, such as the following example:

Example: Example to accept input from a UNIX command

{while("who -u"|getline)
{
#process each line from the who command
}
}

Of course, you can also use the following form:

"command" | getline variable

3. Close the file:

awk allows you to close an input or output file in the program, The method is to use awk's close statement.

close("filename")

filename can be the file opened by getline (it can also be stdin, a variable containing the file name or the exact command used by getline). Or an output file (could be stdout, a variable containing the filename or the exact command using a pipe).

4. Output to a file:

awk allows you to output the results to a file in the following ways:

printf("hello word!")>"datafile"
or
printf("hello word!") >>"datafile"

5. Output to a command

Awk allows the following method to output the result to a command:

printf("hello word!")|"sort-t','"

Mixed programming of awk and shell script

Because awk can be used as a shell command , so awk can be well integrated with shell batch programs, which makes it possible to implement mixed programming of awk and shell programs. The key to realizing hybrid programming is the dialogue between awk and shell script. In other words, it is the information exchange between awk and shell script: awk obtains the required information (usually the value of the variable) from the shell script and executes it in awk The shell command line and shell script send the command execution results to awk for processing, and the shell script reads the execution results of awk, etc.

1.awk reads Shell script program variables

In awk, we can read the variables in the sell scrpit program through "'$variable name'".

Example: In the following example, we will read the variable Name in the sell scrpit program. This variable stores the author of the text myfile, and awk will print out the name.

$cat writename
:
# @(#)
#
.
.
.
Name="Zhang San" nawk 'BEGIN {name="'Name'"; printf("%s written by %s" ,FILENAME,name");}
{...}END{...}' myfile
.
.
.

2. Send the execution result of the shell command to awk for processing

as a kind of information transmission Method, we can pass the result of a shell command to awk for processing through the pipeline (|):

Example: Example awk processes the execution result of the shell command

$who -u | awk '{printf("%s is executing %s",$2,$1)}'

This command will print out the name of the program being executed by the registered terminal.

3. The shell script program reads the execution result of awk

In order to realize the shell script program reads the result of awk execution , we can take some special methods, for example, we can use the variable name = `awk statement` to store the awk execution result into a shell script variable. Of course, we can also use the pipeline method to pass the awk execution result to the shell script. Program processing.

Example: As one of the mechanisms for transmitting messages, UNIX provides a command wall to transmit messages to all its users (meaning write to all). This command allows to send messages to all working users ( Terminal) to send messages. To do this, we can simulate this program through a shell batch program wall.shell (in fact, in older versions, wall is a shell batch program:

$cat wall.shell
:
# @(#) wall.shell: Send a message to each registered terminal
#
cat >/tmp/$$
#User input message text who -u | awk '{print $2}' | while read tty
do
cat /tmp/$$>$tty
done

In this program, awk accepts the execution result of the who -u command. This command prints out the information of all registered terminals, and the second field is registered The device name of the terminal, so use the awk command to extract the device name, and then use the while read tty statement to loop out these file names into the variable (shell script variable) tty as the terminal address for information transmission

4. In awk. Execute the shell command line----embedded function system()

system() is an embedded function that is not suitable for character or numeric types. The function of this function is to process the string passed to it as a parameter. The system processes this parameter as a command, that is to say, executes it as a command line. This gives users the flexibility to execute commands or scripts when needed by their own awk programs.

Example: The following program will use the system embedded function to print the report file prepared by the user. This file is stored in a file named myreport.txt. For simplicity, we only list its END part:

.
.
.
END {close("myreport.txt");system("lp myreport.txt");}

In this example, We first closed the file myreport.txt using the close statement, and then used the system embedded function to send myreport.txt to the printer for printing.

Writing this, I have to say goodbye to my friends. To be honest, these contents are still preliminary knowledge of awk. Computers are always advancing science, and awk is no exception. All this article can do is to help you Make a small start in the long journey ahead, and you have to walk the rest of the way on your own. To be honest, if this article can really bring you some convenience on the way forward, then I will be satisfied!

If you have any questions about this article, please email To:Chizlong@yeah.net or leave a message on the homepage http://chizling.yeah.net.


Appendix:

1.awk’s regular expression metacharacters

escape sequence
^ starts at the beginning of the string and matches
$ starts at the end of the string
. Matches any single string
[ABC ] matches any character within []
[A-Ca-c] matches characters in the range A-C and a-c (in alphabetical order)
[^ABC] matches any character except all characters in []
Desk|Chair matches Desk and Chair Any matching
[ABC][DEF] association. Matches any character among A, B, and C, and must be followed by any character among D, E, and F.
* Matches any character A, B or C that appears 0 or more times
+ Matches any character A, B or C that appears 1 or more times
? Matches an empty string or any character of A, B or C
(Blue|Black)berry Combine regular expressions to match Blueberry or Blackberry

2.awk arithmetic operators

Operator usage
-- ----------------
x^y x raised to the y power
x**y Same as above
x%y Calculate the remainder of x/y (modulo)
x+y x plus y
x-y x minus y
x*y Add 1 after the y value (suffix addition)
--y Use y after subtracting 1 from y (prefix subtraction)
y-- Subtract 1 from y after use (suffix subtraction)
x=y Assign the value of y to x
x+= y Assign the value of x+y to x
x-=y Assign the value of x-y to x
x*=y Assign the value of x*y to x
x/=y Assign the value of x/y to x x %=y Assign the value of x%y to x
x^=y Assign the value of x^y to x
x**=y Assign the value of x**y to x

3.awk allowed tests :

Operator meaning

x==y x is equal to y
x!=y x is not equal to y
x>y x is greater than y
x>=y x is greater than or equal to y
xx~re x matches the regular expression re?
x!~re x does not match the regular expression re?

4.awk operators (in ascending order of priority)

=, +=, - =、 *= 、/= 、 %=
||
&&
> >= < <= == != ~ !~
xy (String concatenation, 'x'y' becomes "xy" )
+ -
* / %
++ --

5.awk built-in variables (predefined variables)

Note: The v item in the table represents the first tool that supports variables (the same below): A=awk, N=nawk,P=POSIX awk,G=gawk

V Variable meaning default value
-------------------------------- -----------------------------
N ARGC The number of command line parameters
G ARGIND The ARGV identifier of the currently processed file
N ARGV command Line parameter array
G CONVFMT Number conversion format %.6g
P ENVIRON UNIX environment variable
N ERRNO UNIX system error message
G FIELDWIDTHS A blank-delimited string of input field widths
A FILENAME The name of the current input file
P FNR The current number of records
A FS Input field separator space
G IGNORECASE Control case sensitivity 0 (case sensitive)
A NF Number of fields in the current record
A NR Number of records that have been read
A OFMT Number output format %.6g
A OFS Output field separator space
A ORS Output record separator new line
A RS Input record separator new line
N RSTART The first string matched by the matching function
N RLENGTH The length of the string matched by the matching function
N SUBSEP Subscript separator "34"

6.awk's built-in function

V function purpose or return value
-------------------------- -----------------------
N gsub(reg,string,target) Replace the string in target every time the regular expression reg matches
N index(search ,string) Returns the position of the search string in string
A length(string) Finds the number of characters in string
N match(string,reg) Returns the position in the string matched by the regular expression reg
N printf(format,variable ) Formatted output, output variables according to the format provided by format.
N split(string,store,delim) Decomposes string into array elements of store according to delimiter delim
N sprintf(format,variable) Returns a formatted data based on format. Variables is the data to be placed in the string
G strftime(format, timestamp) returns a date or time string based on format, timestmp is the time returned by the systime() function
N sub(reg, string, target) When the regular expression reg matches for the first time, replace it in the target string String
A substr(string,position,len) Returns a substring starting with position len characters
P totower(string) Returns the corresponding lowercase character in string
P toupper(string) Returns the corresponding uppercase character in string
A atan(x,y) cotangent of x (radians)
N cos(x) cosine of x (radians)
A exp(x) x power of e
A int(x) integer part of x
A log (x) Natural logarithm of x
N rand() Random number between 0-1
N sin(x) Sine of x (radians)
A sqrt(x) Square root of x
A srand(x) Initialization random number generator. If x is omitted, use system()
G system() returns the elapsed time (in seconds) since January 1, 1970


For more detailed explanations of AWK commands and related articles, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template