⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 awk.1

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻 1
字号:
.TH AWK 1 .SH NAMEawk \- pattern scanning and processing language.SH SYNOPSIS.B awk[.BI \-F c][ prog ] [ file ] ....SH DESCRIPTION.I Awkscans each input.I filefor lines that match any of a set of patterns specified in.IR prog .With each pattern in.I progthere can be an associated action that will be performedwhen a line of a.I filematches the pattern.The set of patterns may appear literally as.I prog,or in a filespecified as.B \-f.IR file ..PPFiles are read in order;if there are no files, the standard input is read.The file name `\-'means the standard input.Each line is matched against thepattern portion of every pattern-action statement;the associated action is performed for each matched pattern..PPAn input line is made up of fields separated by white space.(This default can be changed by using FS,.IR "vide infra" ".)"The fields are denoted $1, $2, ... ;$0 refers to the entire line..PP.PPA pattern-action statement has the form.PP	pattern { action }.PPA missing { action } means print the line;a missing pattern always matches..PPAn action is a sequence of statements.A statement can be one of the following:.PP.nf	if ( conditional ) statement [ else statement ]	while ( conditional ) statement	for ( expression ; conditional ; expression ) statement	break	continue	{ [ statement ] ... }	variable = expression	print [ expression-list ] [ >expression ]	printf format [ , expression-list ] [ >expression ]	next	# skip remaining patterns on this input line 	exit	# skip the rest of the input.fi.PPStatements are terminated bysemicolons, newlines or right braces.An empty expression-list stands for the whole line.Expressions take on string or numeric values as appropriate,and are built using the operators+, \-, *, /, %,  and concatenation (indicated by a blank).The C operators ++, \-\-, +=, \-=, *=, /=, and %=are also available in expressions.Variables may be scalars, array elements(denotedx[i])or fields.Variables are initialized to the null string.Array subscripts may be any string,not necessarily numeric;this allows for a form of associative memory.String constants are quoted "..."..PPThe .I printstatement prints its arguments on the standard output(or on a file if .I >fileis present), separated by the current output field separator,and terminated by the output record separator.The.I printfstatement formats its expression list according to the format(see.IR printf (3))..PPThe built-in function.I lengthreturns the length of its argumenttaken as a string,or of the whole line if no argument.There are also built-in functions.I exp,.I log,.I sqrt,and.IR int .The last truncates its argument to an integer..IR substr(s,\ m,\ n)returns the .IR n -charactersubstring of.I sthat begins at position.IR m .The function.IR sprintf(fmt,\ expr,\ expr,\ ...)formats the expressionsaccording to the.IR printf (3)format given by.I fmtand returns the resulting string..PPPatterns are arbitrary Boolean combinations(!, \(or\(or, &&, and parentheses) of regular expressions andrelational expressions.Regular expressions must be surroundedby slashes and are as in.IR egrep .Isolated regular expressionsin a pattern apply to the entire line.Regular expressions may also occur inrelational expressions..PPA pattern may consist of two patterns separated by a comma;in this case, the action is performed for all linesbetween an occurrence of the first patternand the next occurrence of the second..PP.nfA relational expression is one of the following:.PP.nf	expression matchop regular-expression	expression relop expression.PP.fiwhere a relop is any of the six relational operators in C,and a matchop is either ~ (for contains)or !~ (for does not contain).A conditional is an arithmetic expression,a relational expression,or a Boolean combinationof these..PPThe special patternsBEGINandENDmay be used to capture control before the first input line is readand after the last.BEGIN must be the first pattern, END the last..PPA single character.I cmay be used to separate the fields by startingthe program with.PP	BEGIN { FS = "c" }.PPor by using the.BI \-F coption..PPOther variable names with special meaningsinclude NF, the number of fields in the current record;NR, the ordinal number of the current record;FILENAME, the name of the current input file;OFS, the output field separator (default blank);ORS, the output record separator (default newline);andOFMT, the output format for numbers (default "%.6g")..PP.SH EXAMPLES.PPPrint lines longer than 72 characters:.PP.nf	length > 72.fi.PPPrint first two fields in opposite order:.PP.nf	{ print $2, $1 }.fi.PPAdd up first column, print sum and average:.PP.nf		{ s += $1 }	END	{ print "sum is", s, " average is", s/NR }.fi.PPPrint fields in reverse order:.PP.nf	{ for (i = NF; i > 0; \-\-i) print $i }.fi.PPPrint all lines between start/stop pairs:.PP.nf	/start/, /stop/.fi.PPPrint all lines whose first field is different from previous one:.PP.nf	$1 != prev { print; prev = $1 }.fi.SH SEE ALSO.PPlex(1), sed(1).brA. V. Aho, B. W. Kernighan, P. J. Weinberger,.IAwk \- a pattern scanning and processing language.SH BUGSThere are no explicit conversions between numbers and strings.To force an expression to be treated as a number add 0 to it;to force it to be treated as a string concatenate ""to it.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -