
AWKREFERENCE DEFINITIONS This card describes POSIX AWK, as well as the three freely CONTENTS available awk implementations (see FTP/HTTP Infor mation Action Statements ........................................................ 7 below). Common extensions (in twoormore versions) are Arrays ........................................................................... 11 printed in light blue. Features specific to just one version— AwkProgram Execution ............................................... 4 usually GNU AWK (gawk)—are printed in dark blue. Bit Manipulation Functions (gawk)............................ 16 Exceptions and deprecated features are printed in red. Features Bug Reports.................................................................. 2 mandated by POSIX are printed in black. Closing Redirections .................................................... 12 Several type faces are used to clarify the meaning: Command Line Arguments (standard)......................... 2 • Courier Bold is used for computer input. Command Line Arguments (gawk)............................. 3 • Times Italic is used for emphasis, to indicate user input and for Command Line Arguments (mawk)............................. 4 syntactic placeholders, such as variable or action. Conversions And Comparisons .................................... 9 •Times Roman is used for explanatory text. Copying Permissions.................................................... 18 Definitions .................................................................... 2 number −afloating point number as in ANSI C, such as 3, 2.3, Dynamic Extensions (gawk)....................................... 14 1.4e2 or 4.1E5. Numbers may also be giveninoctal or Environment Variables (gawk).................................... 16 hexadecimal: e.g., 011 or 0x11. Escape Sequences......................................................... 8 escape sequences −aspecial sequence of characters beginning Expressions ................................................................... 11 with a backslash, used to describe otherwise unprintable Fields ............................................................................ 6 characters. (See Escape Sequences below.) FTP/HTTP Information................................................ 18 Historical Features (gawk).......................................... 16 string −agroup of characters enclosed in double quotes. Strings Input Control ................................................................ 12 may contain escape sequences. Internationalization (gawk)......................................... 18 regexp −aregular expression, either a regexp constant enclosed in Lines And Statements................................................... 5 forward slashes, or a dynamic regexp computed at run-time. Localization (gawk)..................................................... 17 Regexp constants may contain escape sequences. Numeric Functions ....................................................... 14 Output Control.............................................................. 12 name −avariable, array or function name. Pattern Elements........................................................... 7 entry(N)−entry entry in section N of the UNIX reference POSIX Character Classes (gawk)................................ 6 manual. Printf Formats ............................................................... 13 Records ......................................................................... 6 pattern −anexpression describing an input record to be matched. Regular Expressions..................................................... 5 action −statements to execute when an input record is matched. Special Filenames......................................................... 14 String Functions ........................................................... 15 rule −apattern-action pair,where the pattern or action may be Time Functions (gawk)................................................ 16 missing. User-defined Functions ................................................ 17 Variables ....................................................................... 8 COMMAND LINE ARGUMENTS (standard) Arnold Robbins wrote this reference card. We thank Brian Command line arguments control setting the field separator, Kernighan and Michael Brennan who reviewed it. setting variables before the BEGIN rule is run, and the location of AWKprogram source code. Implementation-specific command line arguments change the behavior of the running interpreter. OTHER FSF PRODUCTS: −F fs use fs for the input field separator. Free Software Foundation, Inc. −v var=val assign the value val to the variable var before 59 Temple Place — Suite 330 execution of the program begins. Such variable Boston, MA 02111-1307 USA values are available to the BEGIN rule. −f prog-file read the AWK program source from the file Phone: +1-617-542-5942 prog-file,instead of from the first command line Fax(including Japan): +1-617-542-2652 argument. Multiple −f options may be used. E-mail: [email protected] −− signal the end of options. URL: http://www.gnu.org The following options are accepted by both Bell Labs awk and gawk (ignored by gawk,not in mawk). Source Distributions on CD-ROM −mf val set the maximum number of fields to val −mr val set the maximum record size to val DeluxeDistributions Emacs, Gawk, Make and GDB Manuals BUGREPORTS Emacs and GDB References If you find a bug in this reference card, please report it via electronic mail to [email protected]. Copyright © 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. 1 2 Copyright 05-01-02 18:25:12, FSF, Inc. (all) COMMAND LINE ARGUMENTS (gawk) COMMAND LINE ARGUMENTS (mawk) The following options are specific to gawk.You may also use The following options are specific to mawk. ``−W option'' for full POSIX compliance. Long options may −W dump print an assembly listing of the program abbreviated as long as the abbreviation remains unique. to stdout and exit zero. −−assign var=val just like −v. −W exec file read program text from file.Noother −−field-separator fs just like −F. options are processed. Useful with #!. −−file prog-file just like −f. −W interactive unbuffer stdout and line buffer −−compat, −−traditional stdin.Lines are always records, disable gawk-specific extensions (the use of ignoring RS. −−traditional is preferred). −W posix_space \n separates fields when RS = "". −−copyleft, −−copyright −W sprintf=num adjust the size of mawk's internal print the short version of the GNU copyright sprintf buffer. information on stdout. −W version print version and copyright on stdout −−dump-variables[=file] and limit information on stderr and Print a sorted list of global variables, their types exit zero. and final values to file.Ifnofile is provided, The options may be abbreviated using just the first letter,e.g., gawk uses awkvars.out. −We, −Wv and so on. −−gen−po process the program and print a GNU gettext format .po format file on standard output, containing the text of all strings that were AWKPROGRAM EXECUTION marked for localization. AWKprograms are a sequence of pattern-action statements and −−help, −−usage optional function definitions. print a short summary of the available options on stdout,then exit zero. pattern { action statements } −−lint[=fatal] function name(parameter list){statements } warn about constructs that are dubious or non- awk first reads the program source from the prog-file(s), if portable to other awks. With an optional specified, from arguments to −−source, or from the first non- argument of fatal,lint warnings become fatal option argument on the command line. The program text is read errors. as if all the prog-file(s) and command line source texts had been −−lint−old warn about constructs that are not portable to the concatenated. original version of Unix awk. −−non−decimal−data AWKprograms execute in the following order.First, all variable recognize octal and hexadecimal values in input assignments specified via the −v option are performed. Next, data. Use this option with great caution! awk executes the code in the BEGIN rules(s), if any, and then −−posix disable common and GNU extensions. Enable proceeds to read the files 1 through ARGC − 1 in the ARGV interval expressions in regular expression array.(Adjusting ARGC and ARGV thus provides control overthe matching (see Regular Expressions below). input files that will be processed.) If there are no files named on −−profile[=prof_file] the command line, awk reads the standard input. send profiling data to prof_file (default: If a command line argument has the form var=val,itistreated as awkprof.out). With gawk,the profile is just avariable assignment. The variable var will be assigned the value a``pretty printed''version of the program. With val.(This happens after any BEGIN rule(s) have been run.) pgawk,the profile contains execution counts in Command line variable assignment is most useful for the left margin of each statement in the program. dynamically assigning values to the variables awk uses to control −−re−interval howinput is broken into fields and records. It is also useful for enable interval expressions in regular expression controlling state if multiple passes are needed overasingle data matching (see Regular Expressions below). file. Useful if −−posix is not specified. −−source ’text’ If the value of a particular element of ARGV is empty (""), awk use text as AWK program source code. skips overit. −−version print version information on stdout and exit Foreach record in
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages10 Page
-
File Size-