UNIX commands on the APM } setup cutils to make these commands available. ! !expression ] printf format [ , expression-list ] [ >expression ] next # skip remaining patterns on this input line exit # skip the rest of the input Statements are terminated by semicolons, 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 con- catenation (indicated by a blank). The C operators ++, --, +=, -=, *=, /=, and %= are also available in expressions. Variables may be scalars, array elements (denoted x[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 con- stants are quoted "...". The print statement prints its arguments on the standard ----- output (or on a file if >file is present), separated by the ---- current output field separator, and terminated by the output record separator. The printf statement formats its expres- ------ sion list according to the format (see . ------ The built-in function length returns the length of its argu- ------ ment taken as a string, or of the whole line if no argument. There are also built-in functions exp, log, sqrt, and int. --- --- ---- --- The last truncates its argument to an integer. substr(s, m, n) returns the n-character substring of s that ------ - - - - - begins at position m. The function - sprintf(fmt, expr, expr, ...) formats the expressions ------- --- ---- ---- according to the printf(3S) format given by fmt and returns ------ --- the resulting string. Patterns are arbitrary Boolean combinations (!, ||, &&, and parentheses) of regular expressions and relational expres- sions. Regular expressions must be surrounded by slashes and are as in egrep. Isolated regular expressions in a pat- ----- tern apply to the entire line. Regular expressions may also occur in relational expressions. A pattern may consist of two patterns separated by a comma; in this case, the action is performed for all lines between an occurrence of the first pattern and the next occurrence of the second. A relational expression is one of the following: expression matchop regular-expression expression relop expression where 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 combination of these. The special patterns BEGIN and END may be used to capture control before the first input line is read and after the last. BEGIN must be the first pattern, END the last. A single character c may be used to separate the fields by - starting the program with BEGIN { FS = "c" } or by using the -Fc option. - Other variable names with special meanings include 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); and OFMT, the output format for numbers (default "%.6g"). EXAMPLES Print lines longer than 72 characters: length > 72 Print first two fields in opposite order: { print $2, $1 } Add up first column, print sum and average: { s += $1 } END { print "sum is", s, " average is", s/NR } Print fields in reverse order: { for (i = NF; i > 0; --i) print $i } Print all lines between start/stop pairs: /start/, /stop/ Print all lines whose first field is different from previous one: $1 != prev { print; prev = $1 } SEE ALSO A. V. Aho, B. W. Kernighan, P. J. Weinberger, Awk - a pat- --- - ---- tern scanning and processing language ---- -------- --- ---------- -------- BUGS There 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 concaten- ate "" to it. !> !file3 concatenates the first two files and places the result on the third. If no input file is given, or if the argument `-' is encoun- tered, cat reads from the standard input file. Output is --- buffered in 1024-byte blocks unless the standard output is a terminal, in which case it is line buffered. The -u option makes the output completely unbuffered. The -n option displays the output lines preceded by lines numbers, numbered sequentially from 1. Specifying the -b option with the -n option omits the line numbers from blank lines. The -s option crushes out multiple adjacent empty lines so that the output is displayed single spaced. The -v option displays non-printing characters so that they are visible. Control characters print like ^X for control- x; the delete character (octal 0177) prints as ^?. Non- ascii characters (with the high bit set) are printed as M- (for meta) followed by the character of the low 7 bits. A -e option may be given with the -v option, which displays a `$' character at the end of each line. Specifying the -t option with the -v option displays tab characters as ^I. SEE ALSO BUGS Beware of `cat a b >a' and `cat a b >b', which destroy the input files before reading them. !> ! !" are non-terminals, bare lower-case words are terminals that stand for themselves. Bare upper-case words are other lexical tokens: NOTHING means the empty string; NAME means a C identifier; NUMBER means a string of decimal digits; and NL means the new-line character. ::= NOTHING | NL ::= NOTHING | declare NAME as | cast NAME into | explain | help ::= array of | array NUMBER of | function returning | function ( NAME ) returning | pointer to | ::= | * ::= ( ) | [ ] | [ NUMBER ] | ( ) | NAME ::= | | | struct NAME | union NAME | enum NAME ::= int | char | double | float ::= | ::= short | long | unsigned EXAMPLES To declare an array of pointers to functions like malloc(3), do declare fptab as array of pointer to function returning pointer to char The result of this command is char *(*fptab[])() When you see this declaration in someone else's code, you can make sense out of it by doing explain char *(*fptab[])() The proper declaration for signal(2) can- not be described in cdecl's language (it can't be described ----- in C either). An adequate declaration for most purposes is given by declare signal as function returning pointer to function returning int The function declaration that results has two sets of empty parentheses. The author of such a function might wonder where the parameters go. declare sig- nal as function (args) returning pointer to function return- ing int provides the solution: int (*signal(args))() DIAGNOSTICS The declare statement tries to point out constructions that are not supported in C. Also, certain non-portable con- structs are flagged. Syntax errors cause the parser to play dead until a newline is read. SEE ALSO Section 8.4 of the C Reference Manual. BUGS The pseudo-English syntax is excessively verbose. !> ! ! ! ! !'. Except for -b, which may be given with any of the others, the following options are mutually exclusive: -e producing a script of a, c and d commands for the - - - editor ed, which will recreate file2 from file1. -- ----- ----- In connection with -e, the following shell program may help maintain multiple versions of a file. Only an ancestral file ($1) and a chain of version-to-version ed scripts ($2,$3,...) made by -- diff need be on hand. A `latest version' appears ---- on the standard output. (shift; cat $*; echo '1,$p') | ed - $1 Extra commands are added to the output when compar- ing directories with -e, so that the result is a sh(1) script for converting text files which are -- common to the two directories from their state in dir1 to their state in dir2. ---- ---- -f produces a script similar to that of -e, not useful with ed, and in the opposite order. -- -c produces a diff with lines of context. The default is to present 3 lines of context and may be changed, e.g to 10, by -c10. With -c the output format is modified slightly: the output beginning with identification of the files involved and their creation dates and then each change is separated by a line with a dozen *'s. The lines removed from file1 are marked with `-'; those added to file2 are ----- ----- marked `+'. Lines which are changed from one file to the other are marked in both files with `!'. -h does a fast, half-hearted job. It works only when changed stretches are short and well separated, but does work on files of unlimited length. -Dstring causes diff to create a merged version of file1 and ---- ----- file2 on the standard output, with C preprocessor ----- controls included so that a compilation of the result without defining string is equivalent to ------ compiling file1, while defining string will yield ----- ------ file2. ----- -b causes trailing blanks (spaces and tabs) to be ignored, and other strings of blanks to compare equal. FILES /tmp/d????? /usr/lib/diffh for -h /bin/pr SEE ALSO DIAGNOSTICS Exit status is 0 for no differences, 1 for some, 2 for trou- ble. BUGS Editing scripts produced under the -e or -f option are naive about creating lines consisting of a single `.'. When comparing directories with the -b option specified, diff first compares the files ala cmp, and then decides to ---- --- run the diff algorithm if they are not equal. This may ---- cause a small amount of spurious output if the files then turn out to be identical because the only differences are insignificant blank string differences. !> !&2'. !> ! . The append command reads the given text and appends it after the addressed line. `.' is left on the last line input, if there were any, otherwise at the addressed line. Address `0' is legal for this command; text is placed at the beginning of the buffer. (., .)c . The change command deletes the addressed lines, then accepts input text which replaces these lines. `.' is left at the last line input; if there were none, it is left at the line preceding the deleted lines. (., .)d The delete command deletes the addressed lines from the buffer. The line originally after the last line deleted becomes the current line; if the lines deleted were originally at the end, the new last line becomes the current line. e filename The edit command causes the entire contents of the buffer to be deleted, and then the named file to be read in. `.' is set to the last line of the buffer. The number of characters read is typed. `filename' is remembered for possible use as a default file name in a subsequent r or w command. If `filename' is missing, - - the remembered name is used. E filename This command is the same as e, except that no - diagnostic results when no w has been given since the - last buffer alteration. f filename The filename command prints the currently remembered file name. If `filename' is given, the currently remembered file name is changed to `filename'. (1,$)g/regular expression/command list In the global command, the first step is to mark every line which matches the given regular expression. Then for every such line, the given command list is executed with `.' initially set to that line. A single command or the first of multiple commands appears on the same line with the global command. All lines of a multi- line list except the last line must be ended with `\'. A, i, and c commands and associated input are permit- - - - ted; the `.' terminating input mode may be omitted if it would be on the last line of the command list. The commands g and v are not permitted in the command list. - - (.)i . This command inserts the given text before the addressed line. `.' is left at the last line input, or, if there were none, at the line before the addressed line. This command differs from the a com- - mand only in the placement of the text. (., .+1)j This command joins the addressed lines into a single line; intermediate newlines simply disappear. `.' is left at the resulting line. ( . )kx - The mark command marks the addressed line with name x, - which must be a lower-case letter. The address form `'x' then addresses this line. - (., .)l The list command prints the addressed lines in an unam- biguous way: non-graphic characters are printed in two-digit octal, and long lines are folded. The l com- - mand may be placed on the same line after any non-i/o command. (., .)ma - The move command repositions the addressed lines after the line addressed by a. The last of the moved lines - becomes the current line. (., .)n The number command prints the addressed lines with line numbers and a tab at the left. (., .)p The print command prints the addressed lines. `.' is left at the last line printed. The p command may be - placed on the same line after any non-i/o command. (., .)P This command is a synonym for p. - q The quit command causes ed to exit. No automatic write -- of a file is done. Q This command is the same as q, except that no diagnos- - tic results when no w has been given since the last - buffer alteration. ($)r filename The read command reads in the given file after the addressed line. If no file name is given, the remem- bered file name, if any, is used (see e and f com- - - mands). The file name is remembered if there was no remembered file name already. Address `0' is legal for r and causes the file to be read at the beginning of - the buffer. If the read is successful, the number of characters read is typed. `.' is left at the last line read in from the file. ( ., .)s/regular expression/replacement/ or, ( ., .)s/regular expression/replacement/g The substitute command searches each addressed line for an occurrence of the specified regular expression. On each line in which a match is found, all matched strings are replaced by the replacement specified, if the global replacement indicator `g' appears after the command. If the global indicator does not appear, only the first occurrence of the matched string is replaced. It is an error for the substitution to fail on all addressed lines. Any punctuation character may be used instead of `/' to delimit the regular expression and the replacement. `.' is left at the last line substi- tuted. An ampersand `&' appearing in the replacement is replaced by the string matching the regular expression. The special meaning of `&' in this context may be suppressed by preceding it by `\'. The characters `\n' -- where n is a digit, are replaced by the text matched by - the n-th regular subexpression enclosed between `\(' - and `\)'. When nested, parenthesized subexpressions are present, n is determined by counting occurrences of - `\(' starting from the left. Lines may be split by substituting new-line characters into them. The new-line in the replacement string must be escaped by preceding it by `\'. One or two trailing delimiters may be omitted, implying the `p' suffix. The special form `s' followed by no -- delimiters repeats the most recent substitute command on the addressed lines. The `s' may be followed by the letters r (use the most recent regular expression for the left hand side, instead of the most recent left hand side of a substitute command), p (complement the setting of the p suffix from the previous substitu- - tion), or g (complement the setting of the g suffix). - These letters may be combined in any order. (., .)ta - This command acts just like the m command, except that - a copy of the addressed lines is placed after address a - (which may be 0). `.' is left on the last line of the copy. (., .)u The undo command restores the buffer to it's state before the most recent buffer modifying command. The current line is also restored. Buffer modifying com- mands are a, c, d, g, i, k, and v. For purposes of - - - - - - - undo, g and v are considered to be a single buffer - - modifying command. Undo is its own inverse. When ed runs out of memory (at about 8000 lines on any -- 16 bit mini-computer such as the PDP-11) This full undo is not possible, and u can only undo the effect of the - most recent substitute on the current line. This res- tricted undo also applies to editor scripts when ed is -- invoked with the - option. (1, $)v/regular expression/command list This command is the same as the global command g except - that the command list is executed g with `.' initially - set to every line except those matching the regular ------ expression. (1, $)w filename The write command writes the addressed lines onto the given file. If the file does not exist, it is created. The file name is remembered if there was no remembered file name already. If no file name is given, the remembered file name, if any, is used (see e and f com- - - mands). `.' is unchanged. If the command is successful, the number of characters written is printed. (1, $)W filename This command is the same as w, except that the - addressed lines are appended to the file. (1, $)wq filename This command is the same as w except that afterwards a - q command is done, exiting the editor after the file is - written. x A key string is demanded from the standard input. Later r, e and w commands will encrypt and decrypt the - - - text with this key by the algorithm of crypt(1). An ----- explicitly empty key turns off encryption. (.+1)z or, (.+1)zn - This command scrolls through the buffer starting at the addressed line. 22 (or n, if given) lines are printed. - The last line printed becomes the current line. The value n is sticky, in that it becomes the default for - future z commands. - ($)= The line number of the addressed line is typed. `.' is unchanged by this command. ! The remainder of the line after the `!' is sent to sh(1) to be interpreted as a command. `.' is -- unchanged. (.+1,.+1) An address alone on a line causes the addressed line to be printed. A blank line alone is equivalent to `.+1p'; it is useful for stepping through text. If two addresses are present with no intervening semicolon, ed -- prints the range of lines. If they are separated by a semicolon, the second line is printed. If an interrupt signal (ASCII DEL) is sent, ed prints -- `?interrupted' and returns to its command level. Some size limitations: 512 characters per line, 256 charac- ters per global command list, 64 characters per file name, and, on mini computers, 128K characters in the temporary file. The limit on the number of lines depends on the amount of core: each line takes 2 words. When reading a file, ed discards ASCII NUL characters and -- all characters after the last newline. It refuses to read files containing non-ASCII characters. FILES /tmp/e* edhup: work is saved here if terminal hangs up SEE ALSO B. W. Kernighan, A Tutorial Introduction to the ED Text Edi- - -------- ------------ -- --- -- ---- ---- tor --- B. W. Kernighan, Advanced editing on UNIX -------- ------- -- ---- DIAGNOSTICS `?name' for inaccessible file; `?self-explanatory message' for other errors. To protect against throwing away valuable work, a q or e - - command is considered to be in error, unless a w has - occurred since the last buffer change. A second q or e will - - be obeyed regardless. BUGS The l command mishandles DEL. - The undo command causes marks to be lost on affected lines. ---- The x command, -x option, and special treatment of hangups - only work on UNIX. !> !', see -- ---- -e expression ---------- Same as a simple expression argument, but useful when ---------- the expression begins with a -. ---------- -f file ---- The regular expression (egrep) or string list (fgrep) ----- ----- is taken from the file. ---- In all cases the file name is shown if there is more than one input file. Care should be taken when using the charac- ters $ * [ ^ | ( ) and \ in the expression as they are also ---------- meaningful to the Shell. It is safest to enclose the entire expression argument in single quotes ' '. ---------- Fgrep searches for lines that contain one of the (newline- ----- separated) strings. ------- Egrep accepts extended regular expressions. In the follow- ----- ing description `character' excludes newline: A \ followed by a single character other than newline matches that character. The character ^ matches the beginning of a line. The character $ matches the end of a line. A . (period) matches any character. A single character not otherwise endowed with special meaning matches that character. A string enclosed in brackets [] matches any single character from the string. Ranges of ASCII character codes may be abbreviated as in `a-z0-9'. A ] may occur only as the first character of the string. A literal - must be placed where it can't be mistaken as a range indicator. A regular expression followed by an * (asterisk) matches a sequence of 0 or more matches of the regular expression. A regular expression followed by a + (plus) matches a sequence of 1 or more matches of the regular expression. A regular expression followed by a ? (question mark) matches a sequence of 0 or 1 matches of the regular expression. Two regular expressions concatenated match a match of the first followed by a match of the second. Two regular expressions separated by | or newline match either a match for the first or a match for the second. A regular expression enclosed in parentheses matches a match for the regular expression. The order of precedence of operators at the same parenthesis level is [] then *+? then concatenation then | and newline. Ideally there should be only one grep, but we don't know a ---- single algorithm that spans a wide enough range of space- time tradeoffs. SEE ALSO DIAGNOSTICS Exit status is 0 if any matches are found, 1 if none, 2 for syntax errors or inaccessible files. BUGS Lines are limited to 256 characters; longer lines are trun- cated. !> ! ! ! !. -------- Interrupt and quit cause the target to be deleted unless the target is a directory or depends on the special name `.PRE- CIOUS'. Other options: -i Equivalent to the special entry `.IGNORE:'. -k When a command returns nonzero status, abandon work on the current entry, but continue on branches that do not depend on the current entry. -n Trace and print, but do not execute the commands needed to update the targets. -t Touch, i.e. update the modified date of targets, without executing any commands. -r Equivalent to an initial special entry `.SUFFIXES:' with no list. -s Equivalent to the special entry `.SILENT:'. FILES makefile, Makefile SEE ALSO S. I. Feldman Make - A Program for Maintaining Computer Pro- ---- - ------- --- ----------- -------- ---- grams ----- BUGS Some commands return nonzero status inappropriately. Use -i to overcome the difficulty. Commands that are directly executed by the shell, notably cd(1), are ineffectual across newlines in make. -- ---- !> ! ! ! ! ! ! ! ! !file2 SEE ALSO BUGS Won't handle ASCII NUL in string1 or string2; always deletes ------- ------- NUL from input. !> ! ! ! ! !