Show Menu
Cheatography

awk-4p Cheat Sheet (DRAFT) by

merging pages 4 and 5 of awk (english) Cheat Sheet by TME520 to save space

This is a draft cheat sheet. It is a work in progress and is not finished yet.

I/O Statements (cont)

print expr-list >file
Prints expres­sions on file. Each expression is separated by the value of the OFS variable. The output record is terminated with the value of the ORS variable.
printf fmt, expr-list
Format and print.
printf fmt, expr-list
>file
Format and print on file.
system(cmd-line)
Execute the command cmd-line, and return the exit status.
fflush([file])
Flush any buffers associated with the open output file or pipe file. If file is missing, then stdout is flushed. If file is the null string, then all open output files and pipes have their buffers flushed.
print ... >> file
Appends output to the file.
print ... | command
Writes on a pipe.
print ... |& command
Sends data to a co-pro­​cess.

Time Functions

systime()
Returns the current time of day as the number of seconds since the Epoch (1970-­01-01 00:00:00 UTC on POSIX systems).
mktime​(da​tespec)
Turns datespec into a time stamp of the same form as returned by systime(). The datespec is a string of the form YYYY MM DD HH MM SS [DST].
strftime([format
[, timestamp]
])
Formats timestamp according to the specif­ication in format. The timestamp should be of the same form as returned by systime(). If timestamp is missing, the current time of day is used. If format is missing, a default format equivalent to the output of date(1) is used.
 

GNU AWK’s Command Line Argument Summary

-F fs or
--field-separator fs
Use fs for the input field separator (the value of the FS predefined variable).
-v var=val or
--assign var=val
Assign the value val to the variable var, before execution of the program begins. Such variable values are available to the BEGIN block of an AWK program.
-f program-file or
--file program-file
Read the AWK program source from the file progra­m-file, instead of from the first command line argument. Multiple -f
(or --file) options may be used.
-mf NNN or
-mr NNN
Set various memory limits to the value NNN. The f flag sets the maximum number of fields, and the r flag sets the maximum record size (ignored by gawk, since gawk has no pre-de­fined limits).
-W compat or
-W traditional or
--compat--traditional
Run in compat­ibility mode. In compat­ibility mode, gawk behaves identi­cally to UNIX awk; none of the GNU-sp­ecific extensions are recogn­ized.
-W dump-variables[=file]
or --dump-variables[=file]
Print a sorted list of global variables, their types and final values to file. If no file is provided, gawk uses a file named awkvar­s.out in the current directory.
-W help or
-W usage or
--help or
--usage
Print a relatively short summary of the available options on the standard output.