awk

From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it (how to get started).

awk is a scripting language for data extraction often used in tandem with sed and grep for complex reporting needs. While large awk programs are possible, the language itself was intended primarily to be used to construct one-liners to filter data and perform simple computations.

Emerge

root #emerge --ask virtual/awk

Configuration

Environment variables

  • AWKPATH a list of directories searches to find file names passed at runtime with the --file option.
  • AWKLIBPATH a list of directories searches to find file names passed at runtime with the --load option.
  • GAWK_READ_TIMEOUT the amount of time (in milliseconds) awk waits for input before giving up.
  • GAWK_SOCK_RETRIES the total number of retries when reading data from a socket.
  • GAWK_MSEC_SLEEP the amount of time (in milliseconds) awk sleeps between retries.
  • POSIXLY_CORRECT duplicates the --posix switch.

Usage

Invocation

user $awk --help
Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
POSIX options:		GNU long options: (standard)
	-f progfile		--file=progfile
	-F fs			--field-separator=fs
	-v var=val		--assign=var=val
Short options:		GNU long options: (extensions)
	-b			--characters-as-bytes
	-c			--traditional
	-C			--copyright
	-d[file]		--dump-variables[=file]
	-D[file]		--debug[=file]
	-e 'program-text'	--source='program-text'
	-E file			--exec=file
	-g			--gen-pot
	-h			--help
	-i includefile		--include=includefile
	-I			--trace
	-l library		--load=library
	-L[fatal|invalid|no-ext]	--lint[=fatal|invalid|no-ext]
	-M			--bignum
	-N			--use-lc-numeric
	-n			--non-decimal-data
	-o[file]		--pretty-print[=file]
	-O			--optimize
	-p[file]		--profile[=file]
	-P			--posix
	-r			--re-interval
	-s			--no-optimize
	-S			--sandbox
	-t			--lint-old
	-V			--version

To report bugs, see node `Bugs' in `gawk.info'
which is section `Reporting Problems and Bugs' in the
printed version.  This same information may be found at
https://www.gnu.org/software/gawk/manual/html_node/Bugs.html.
PLEASE do NOT try to report bugs by posting in comp.lang.awk,
or by using a web forum such as Stack Overflow.

gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.

Examples:
	awk '{ sum += $1 }; END { print sum }' file
	awk -F: '{ print $1 }' /etc/passwd

Removal

Unmerge

root #emerge --ask --depclean --verbose virtual/awk

See also

  • ed — a line-based text editor with support for regular expressions
  • sed — a program that uses regular expressions to programmatically modify streams of text
  • grep — a tool for searching text files with regular expressions
  • Perl — a general purpose interpreted programming language with a powerful regular expression engine.
  • Raku — a high-level, general-purpose, and gradually typed programming language.