gawk(1)


NÉV

gawk - mintakeresô és feldolgozó nyelv

HASZNÁLAT

gawk [ POSIX vagy GNU stílusú opciók ] -f program-file [ -- ] file ...
gawk [ POSIX vagy GNU stílusú opciók ] [ -- ] program-szöveg file ...

LEÍRÁS

A Gawk az AWK programozási nyelv GNU Project-beli megvalósítása. Megfelel a nyelv POSIX 1003.2 Command Language And Utilities Standard által megadott definíciójának. Ez a verzió a "The AWK Programming Language" (Aho, Kernighan, and Weinberger) címû leíráson alapszik, néhány kiegészítô tulajdonsággal ellátva, amelyeket a UNIX-os awk System V Release 4 verziójában definiáltak. A Gawk ezeken kívül tartalmaz néhány GNU-specifikus kiegészítést is.

A parancssor tartalmazza magát a gawk-ot, az AWK program szövegét (ha nem a -f vagy --file kapcsolóval adjuk meg), valamint azokat az értékeket, amelyeket az ARGC és ARGV elôre definiált változókban lehet majd elérni.

KAPCSOLÓK

A Gawk kapcsolók lehetnek a hagyományos POSIX egy betûből álló kapcsolók, vagy a GNU stílusú hosszabb kapcsolók. A POSIX kapcsolók egy ``-'' jellel kezdődnek , míg a GNU hosszú kapcsolók ``--'' jellel. A GNU stílusú hosszú kapcsolók használhatóak mind a GNU-specifikus , mind a POSIX által meghatározott lehetőségekhez. Az AWK más implementációi lehet , hogy csak a hagyományos , egy betûs kapcsolókat fogadják el.

A POSIX szabványnak megfelelően , gawk -specific opciókat a -W opció argumentumaként lehet megadni . Több -W kapcsolót is meg lehet adni, illetve több argumentumot vesszővel elválasztva , vagy idézőjelben ,szóközökkel elválasztva. A -W opció argumentumaiban a kis és nagybetûket nem különböztetjük meg . Minden -W opciónak van egy megfelelő GNU stílusú hosszú kapcsolója, amint az lejjebb részletezve van. A GNU stílusú kapcsolók argumentumai lehetnek a kapcsoló után egy = jellel elválasztva , szóközök nélkül , vagy megadhatók a következő parancssorban.

A Gawk a következő kapcsolókat fogadja el:

-F fs

--field-separator= fs
Az fs lesz a mezőket elválasztó jel (az előre definiált FS változó értéke).

-v var=val

--assign=var=val
A var , változó a val , értéket veszi fel , mielőtt a program futása elkezdődne. A változók értékei elérhetők az AWK program BEGIN blokkjának számára.

-f program-file

--file= program-file
Az AWK program forrását a program-file -ból olvassa be , nem az első parancssorból. Több -f (vagy --file ) kapcsoló is használható.

-mf= NNN

-mr= NNN
A különböző memória limitek NNN értékre állítja be. Az f flag beállítja a mezők maximális számát , az r flag beállítja a maximum record méretet. Ez a két flag és a -m kapcsoló az AT&T Bell Labs kísérleti UNIX awk -ból származik. Ezeket a gawk nem veszi figyelembe , amióta a gawk -nak nincsenek előre definiált limitek.

-W compat

--compat
Compatibility módban való futtatás. Compatibility módban a gawk ugyanúgy viselkedi , mint a UNIX awk ; a GNU-specifikus kiterjesztéseket nem ismeri fel. További információk a "GNU EXTENSIONS" részben (lásd alább).

-W copyleft

-W copyright

--copyleft

--copyright
A GNU copyright információ rövid változatát kiírja az error output-ra.

-W help

-W usage

--help

--usage
Egy viszonylag rövid összefoglalót ír ki az error kimenetre az elérhetö funkciókról. A GNU szabványnak megfelelöen ezek az opciók azonalli sikeres kilépést eredményeznek.

-W lint

--lint
Figyelmeztet az olyan konstrukciókra, amelyek valószínüleg, vagy egyáltalán nem átvihetök más AWK implementációkra.

-W nostalgia

--nostalgia
Egy pillanatnyi nosztalgiát nyújt a régi awk felhasznalóknak.

-W posix

--posix
Ez az opció a kompatibilitási üzemmódba kapcsol, a következö megszorításokkal:

  • A \x "escape"- sorozat nem használható.
  • A function kulcsszónak megfelelö func szinoníma nem használható.
  • A ** és a **= operátorok nem helyettesíthetik a ^ illetve ^= operátorokat.
  • -W source= program-text

    --source= program-text
    A program-text paraméter az AWK program forráskódját tartalmazza. Ez az opció lehetövé teszi a konyvtári függvények (elérhetök a -f és --file opciókkal) és a parancssorban megadott forráskód együttes használatát. Elsösorban közepes és nagyméretü AWK programokhoz valamint parancsfájlokhoz való.

    A "-W source=" formában megadott opció a parancssor egész hátralevö részét a program-text ; paraméternek tekinti, más -W opciók nem használhatók ebben az argumentumban.

    -W version

    --version
    Információt ír az error kimenetre a gawk ezen másolatáról. Ez az opció föként arra szolgál, hogy eldönthesse, hogy a gawk ezen másolata megfelel-e a Free Software Foundation által forgalmazott legfrissebb verziónak. A GNU szabványnak megfelelöen ezek az opciók azonalli sikeres kilépést eredményeznek.

    --
    Az opciók végét jelzi, így lehetövé teszi további ``-'' kezdetü paraméterek átadását magának az AWK programnak. Ez elsösorban a POSIX paraméter feldolgozási konvencióival való megfelelést hivatott szolgálni.

    Kompatibilitási üzemmódban minden más opció illegálisnak számít, de máskülönben figyelmen kívü hagyott. Normál üzemmódban, ha a program-text paraméter adott, akkor az ismeretlen kapcsolók feldolgozásra az AWK-nak továbbítódnak az ARGV tömbben. Ez különösen hasznos AWK programok futtatásánál a ``#!'' interpreter mechanizmuson keresztül.

    AWK PROGRAM EXECUTION

    An AWK program consists of a sequence of pattern-action statements and optional function definitions.

    pattern { action statements }
    function name(parameter list) { statements }

    Gawk first reads the program source from the program-file (s) if specified, from arguments to "-W source=" , or from the first non-option argument on the command line. The -f and "-W source=" options may be used multiple times on the command line. Gawk will read the program text as if all the program-file s and command line source texts had been concatenated together. This is useful for building libraries of AWK functions, without having to include them in each new AWK program that uses them. It also provides the ability to mix library functions with command line programs.

    The environment variable AWKPATH specifies a search path to use when finding source files named with the -f option. If this variable does not exist, the default path is ".:/usr/lib/awk:/usr/local/lib/awk". If a file name given to the -f option contains a ``/'' character, no path search is performed.

    Gawk executes AWK programs in the following order. First, all variable assignments specified via the -v option are performed. Next, gawk compiles the program into an internal form. Then, gawk executes the code in the BEGIN block(s) (if any), and then proceeds to read each file named in the ARGV array. If there are no files named on the command line, gawk reads the standard input.

    If a filename on the command line has the form var = val it is treated as a variable assignment. The variable var will be assigned the value val . (This happens after any BEGIN block(s) have been run.) Command line variable assignment is most useful for dynamically assigning values to the variables AWK uses to control how input is broken into fields and records. It is also useful for controlling state if multiple passes are needed over a single data file.

    If the value of a particular element of ARGV is empty (""), gawk skips over it.

    For each line in the input, gawk tests to see if it matches any pattern in the AWK program. For each pattern that the line matches, the associated action is executed. The patterns are tested in the order they occur in the program.

    Finally, after all the input is exhausted, gawk executes the code in the END block(s) (if any).

    VARIABLES AND FIELDS

    AWK variables are dynamic; they come into existence when they are first used. Their values are either floating-point numbers or strings, or both, depending upon how they are used. AWK also has one dimensional arrays; arrays with multiple dimensions may be simulated. Several pre-defined variables are set as a program runs; these will be described as needed and summarized below.

    Fields

    As each input line is read, gawk splits the line into fields , using the value of the FS variable as the field separator. If FS is a single character, fields are separated by that character. Otherwise, FS is expected to be a full regular expression. In the special case that FS is a single blank, fields are separated by runs of blanks and/or tabs. Note that the value of IGNORECASE (see below) will also affect how fields are split when FS is a regular expression.

    If the FIELDWIDTHS variable is set to a space separated list of numbers, each field is expected to have fixed width, and gawk will split up the record using the specified widths. The value of FS is ignored. Assigning a new value to FS overrides the use of FIELDWIDTHS , and restores the default behavior.

    Each field in the input line may be referenced by its position, $1 , $2 , and so on. $0 is the whole line. The value of a field may be assigned to as well. Fields need not be referenced by constants:

    n = 5
    print $n

    prints the fifth field in the input line. The variable NF is set to the total number of fields in the input line.

    References to non-existent fields (i.e. fields after $NF ) produce the null-string. However, assigning to a non-existent field (e.g., "$(NF+2) = 5" ) will increase the value of NF , create any intervening fields with the null string as their value, and cause the value of $0 to be recomputed, with the fields being separated by the value of OFS . References to negative numbered fields cause a fatal error.

    Built-in Variables

    AWK's built-in variables are:

    ARGC
    The number of command line arguments (does not include options to gawk , or the program source).

    ARGIND
    The index in ARGV of the current file being processed.

    ARGV
    Array of command line arguments. The array is indexed from 0 to ARGC - 1. Dynamically changing the contents of ARGV can control the files used for data.

    CONVFMT
    The conversion format for numbers, "%.6g", by default.

    ENVIRON
    An array containing the values of the current environment. The array is indexed by the environment variables, each element being the value of that variable (e.g., ENVIRON["HOME"] might be /u/arnold ). Changing this array does not affect the environment seen by programs which gawk spawns via redirection or the system() function. (This may change in a future version of gawk .)

    ERRNO
    If a system error occurs either doing a redirection for getline , during a read for getline , or during a close() , then ERRNO will contain a string describing the error.

    FIELDWIDTHS
    A white-space separated list of fieldwidths. When set, gawk parses the input into fields of fixed width, instead of using the value of the FS variable as the field separator. The fixed field width facility is still experimental; expect the semantics to change as gawk evolves over time.

    FILENAME
    The name of the current input file. If no files are specified on the command line, the value of FILENAME is ``-''. However, FILENAME is undefined inside the BEGIN block.

    FNR
    The input record number in the current input file.

    FS
    The input field separator, a blank by default.

    IGNORECASE
    Controls the case-sensitivity of all regular expression operations. If IGNORECASE has a non-zero value, then pattern matching in rules, field splitting with FS , regular expression matching with ~ and !~ , and the gsub() , index() , match() , split() , and sub() pre-defined functions will all ignore case when doing regular expression operations. Thus, if IGNORECASE is not equal to zero, /aB/ matches all of the strings "ab", "aB", "Ab", and "AB". As with all AWK variables, the initial value of IGNORECASE is zero, so all regular expression operations are normally case-sensitive.

    NF
    The number of fields in the current input record.

    NR
    The total number of input records seen so far.

    OFMT
    The output format for numbers, "%.6g", by default.

    OFS
    The output field separator, a blank by default.

    ORS
    The output record separator, by default a newline.

    RS
    The input record separator, by default a newline. RS is exceptional in that only the first character of its string value is used for separating records. (This will probably change in a future release of gawk .) If RS is set to the null string, then records are separated by blank lines. When RS is set to the null string, then the newline character always acts as a field separator, in addition to whatever value FS may have.

    RSTART
    The index of the first character matched by match() ; 0 if no match.

    RLENGTH
    The length of the string matched by match() ; -1 if no match.

    SUBSEP
    The character used to separate multiple subscripts in array elements, by default "\034".

    Tömbök

    A tömbök indexhatárait szögletes zárójelben levő kifejezéssel adjuk meg ( [ " és " ] ). Ha a kifejezés egy kifejezés lista ( kif ", " kif " ...)" akkor a tömb indexeit az a sztring határozza meg, amely a kifejezések (sztring) értékeineknek konkatenációjával jött létre. Ezeket a kifejezéseket SUBSEP változó választja el. Ezzel a lehetőséggel többdimenziós tömböket szimulálhatunk. Például:

    i = "A" ; j = "B" ; k = "C"
    x[i, j, k] = "hello, world\n"

    a "hello, world\n" sztringet az x tömb azon eleméhez rendeli amelyet az "A\034B\034C" sztring határoz meg. Az AWK-ban minden tömb hasonló abban az értelemben, hogy sztringértékekkel indexeljük őket.

    Az in különleges operátort if vagy while kifejezésben használhatjuk arra, hogy megnézzük, hogy a tömbnek van-e egy meghatározott értékű indexe.

    if (val in array)
            print array[val]
    

    Ha a tömbnek több indexe van, akkor az "(i, j) in array" alakot használjuk.

    Az in szerkezetet for ciklusban is használhatjuk, ha végig akarunk menni a tömb elemein.

    A tömb egy elemét a delete paranccsal törölhetjük. A delete segítségével a tömb teljes tartalmát is törölhetjük.

    A változók típusa és konverziók

    A változók és mezők (lebegőpontos) számok vagy sztringek (vagy mindkettő) lehetnek. A változó értékének értelmezése a kontextus alapján történik. Ha numerikus kifejezésben használjuk akkor számként, ha pedig sztringként használjuk akkor sztringként kezeli őket a gép.

    Ha változót mindenképp számként akarjuk kezelni, akkor adjuk hozzá 0-át, ha pedig sztringként, akkor üres sztringet fűzzünk hozzá.

    Ha sztringet számmá kell konvertálni, akkor a konverzió az atof (3) segítségével történik. Szám konverziója sztringgé CONVFMT értékének segítségével történik, amely formátum sztringje sprintf (3)-nek, ahol a változó numerikus értéke az argumentum. Annak ellenére, hogy az AWK-ban minden szám lebegőpontos, a gép az egész számokat mindig integer típusúvá konvertálja. Tehát a

    CONVFMT = "%2.2f"
    a = 12
    b = a ""
    

    módon megadott változónak b a sztringértéke "12", nem pedig "12.00".

    A Gawk az összehasonlításokat a következőképpen végzi: Ha a két változó numerikus, akkor numerikusan hasonlítja őket össze. Ha az egyik érték numerikus a másik olyan sztring, amely egy szám, akkor az összehasonlítás numerikus. Egyéként a numerikus értékeket sztringgé alakítja, és sztringként történik az összahasonlítás. Két sztringet nyilván sztringként hasonlít össze. A POSIX szabványban, ha két sztring tartalma szám, akkor numerikus az összahasonlítás. Viszont ez nyilvánvalóan helytelen és a gawk nem így csinálja.

    Ha a változóknak nem adunk kezdőértéket akkor a 0 és a "" (üres sztring) értéket veszik fel.

    MINTÁK ÉS MŰVELETEK

    Az AWK sor orientált nyelv. A minta jön először, és aztán a művelet. A műveleteket a { és } közé tesszük. A minta vagy a művelet egyike hiányozhat, de természetesen mindkettő nem. A hiányzó műveletnek a

    "{ print }"

    felel meg, ami egy egész sort ír ki.

    A megjegyzések a "#" jellel kezdődnek, és a sor végéig tartanak. Az állításokat üres sorral is elválaszthatjuk. Általában egy állítás végét az újsor jelenti, kivéve ha a sor végén a ",", "{", "?", ":", "&&", vagy "||" jelek valamelyike van. Azok az állítások, amelyeknél a sor végén do vagy else van, a automatikusan következő sorban folytatódnak. Más esetben ha a sort "\" jellel zárjuk, akkor az újsor figyelmen kívül marad.

    Ha több állítást írunk egy sorba, akkor őket a ";" jellel kell elválasztanunk. Ez a minta-művelet pár műveleti részén belüli állításokra (általános eset) és a magukra a minta-műveletek állításaira is vonatkozik.

    Patterns

    AWK patterns may be one of the following:

    BEGIN
    END
     / regular expression /
    relational expression
     pattern  &&  pattern
     pattern  ||  pattern
     pattern  ?  pattern  :  pattern
     ( pattern )
     !  pattern
     pattern1 ,  pattern2
    

    BEGIN and END are two special kinds of patterns which are not tested against the input. The action parts of all BEGIN patterns are merged as if all the statements had been written in a single BEGIN block. They are executed before any of the input is read. Similarly, all the END blocks are merged, and executed when all the input is exhausted (or when an exit statement is executed). BEGIN and END patterns cannot be combined with other patterns in pattern expressions. BEGIN and END patterns cannot have missing action parts.

    For / regular expression / patterns, the associated statement is executed for each input line that matches the regular expression. Regular expressions are the same as those in egrep (1), and are summarized below.

    A relational expression may use any of the operators defined below in the section on actions. These generally test whether certain fields match certain regular expressions.

    The && , || , and ! operators are logical AND, logical OR, and logical NOT, respectively, as in C. They do short-circuit evaluation, also as in C, and are used for combining more primitive pattern expressions. As in most languages, parentheses may be used to change the order of evaluation.

    The ?: operator is like the same operator in C. If the first pattern is true then the pattern used for testing is the second pattern, otherwise it is the third. Only one of the second and third patterns is evaluated.

    The pattern1 , pattern2 form of an expression is called a range pattern . It matches all input records starting with a line that matches pattern1 , and continuing until a record that matches pattern2 , inclusive. It does not combine with any other sort of pattern expression.

    Regular Expressions

    Regular expressions are the extended kind found in egrep . They are composed of characters as follows:

    c
    matches the non-metacharacter c .

    \c
    matches the literal character c .

    .
    matches any character except newline.

    ^
    matches the beginning of a line or a string.

    $
    matches the end of a line or a string.

    [ abc... ]
    character class, matches any of the characters abc... .

    [^ abc... ]
    negated character class, matches any character except abc... and newline.

    r1 | r2
    alternation: matches either r1 or r2 .

    r1r2
    concatenation: matches r1 , and then r2 .

    r +
    matches one or more r 's.

    r *
    matches zero or more r 's.

    r ?
    matches zero or one r 's.

    ( r )
    grouping: matches r .

    The escape sequences that are valid in string constants (see below) are also legal in regular expressions.

    Actions

    Action statements are enclosed in braces, { and } . Action statements consist of the usual assignment, conditional, and looping statements found in most languages. The operators, control statements, and input/output statements available are patterned after those in C.

    Operators

    The operators in AWK, in order of increasing precedence, are

    = += -=

    *= /= %= ^=
    Assignment. Both absolute assignment ( var = value ) and operator-assignment (the other forms) are supported.

    ?:
    The C conditional expression. This has the form expr1 ? expr2 : expr3 . If expr1 is true, the value of the expression is expr2 , otherwise it is expr3 . Only one of expr2 and expr3 is evaluated.

    ||
    Logical OR.

    &&
    Logical AND.

    ~ !~
    Regular expression match, negated match. NOTE: Do not use a constant regular expression ( /foo/ ) on the left-hand side of a ~ or !~ . Only use one on the right-hand side. The expression /foo/ ~ exp has the same meaning as (($0 ~ /foo/) ~ exp). This is usually not what was intended.

    < >

    <= >=

    != ==
    The regular relational operators.

    blank
    String concatenation.

    + -
    Addition and subtraction.

    * / %
    Multiplication, division, and modulus.

    + - !
    Unary plus, unary minus, and logical negation.

    ^
    Exponentiation (** may also be used, and **= for the assignment operator).

    ++ --
    Increment and decrement, both prefix and postfix.

    $
    Field reference.

    Vezérlô utasítások

    A vezérlô utasítások a következôek:

    if (feltétel) utasítás [ else utasítás ]
    while (feltétel) utasítás 
    do utasítás while (feltétel)
    for (kif1; kif2; kif3) utasítás
    for (változó in tömb) utasítás
    break
    continue
    delete tömb[index]
    delete tömb
    exit [ kifejezés ]
    { utasítások } 
    

    I/O Utasítások

    Az input/output utasítások a következôek:

    close( filename )
    File bezárása (vagy pipe, lásd lejjebb).

    getline
    Beállítja a $0-t az input következö rekordjából ; átállítja : NF , NR , FNR .

    getline < file
    Beállítja a $0-t a file -nak a következô rekordjából ; átállítja : NF .

    getline változó
    Beállítja a változót az input következö rekordjából ; átállítja : NF , FNR .

    getline változó < file
    Beállítja a változót a file-nak a következô rekordjából ;

    next
    Megállítja az aktuális input rekord feldolgozását. A következö rekord beolvasódik és megkezdôdik a feldolgozása az AWK program elsô mintájától. Ha a bemenô adatok végét elérné, akkor az END blokk(ok), ha egyáltalán van, végrehajtódik.

    nextfile
    Megállítja az aktuális file feldolgozását. A következô input rekord beolvasódik a következô input file-ból. A FILENAME aktualizálódik, FNR 1-re állítódik, a feldolgozás az AWK program elsô mintájától folytatódik. Ha a bemenô adatok végét elérné, akkor az END blokk(ok), ha egyáltalán van, végrehajtódik.

    print
    Kiírja az aktuális rekordot.

    print kifejezés-lista
    Kiírja a kifejezéseket. A kifejezések az OFS változó értékével vannak elvásztva. Az output rekord az ORS változó étékével végzôdik.

    print kifejezés-lista > file
    Kiírja a kifejezéseket file-ba. A kifejezések az OFS változó értékével vannak elvásztva. Az output rekord az ORS változó étékével végzôdik.

    printf formátum , kifejezés-lista
    Formázott kiírás.

    printf formátum ,kifejezés-lista > file
    Formázott kiírás a file-ba.

    system( parancssor )
    Végrehajta a parancssort és visszaadja a kilépési kósi kódot. (Ez valószínûleg non-POSIX rendszereken nem elérhetô.)

    Más input/output átirányísok szintén megengedettek. A print-nél és a printf-nél a >> file hozzáfûzi az outputot a file-hoz, míg a | command pipe-ba továbbítja. Hasonlóan a command | getline a getline-nak továbbít. A getline parancs 0-t ad vissza ha eléri a file végét, hiba esetén pedig -1 -et.

    The printf Statement

    The AWK versions of the printf statement and sprintf() function (see below) accept the following conversion specification formats:

    %c
    An ASCII character. If the argument used for %c is numeric, it is treated as a character and printed. Otherwise, the argument is assumed to be a string, and the only first character of that string is printed.

    %d
    A decimal number (the integer part).

    %i
    Just like %d .

    %e
    A floating point number of the form [-]d.ddddddE[+-]dd .

    %f
    A floating point number of the form [-]ddd.dddddd .

    %g
    Use e or f conversion, whichever is shorter, with nonsignificant zeros suppressed.

    %o
    An unsigned octal number (again, an integer).

    %s
    A character string.

    %x
    An unsigned hexadecimal number (an integer).

    %X
    Like %x , but using ABCDEF instead of abcdef .

    %%
    A single % character; no argument is converted.

    There are optional, additional parameters that may lie between the % and the control letter:

    -
    The expression should be left-justified within its field.

    width
    The field should be padded to this width. If the number has a leading zero, then the field will be padded with zeros. Otherwise it is padded with blanks. This applies even to the non-numeric output formats.

    . prec
    A number indicating the maximum width of strings or digits to the right of the decimal point.

    The dynamic width and prec capabilities of the ANSI C printf() routines are supported. A * in place of either the width or prec specifications will cause their values to be taken from the argument list to printf or sprintf() .

    Special File Names

    When doing I/O redirection from either print or printf into a file, or via getline from a file, gawk recognizes certain special filenames internally. These filenames allow access to open file descriptors inherited from gawk 's parent process (usually the shell). Other special filenames provide access information about the running gawk process. The filenames are:

    /dev/pid
    Ezt a file-t olvasva a jelenlegi processz ID-jével tér vissza decimális alakban, újsor-ral lezárva.

    /dev/ppid
    Ezt a file-t olvasva a jelenlegi processz szülôprocesszének ID-jével tér vissza decimális alakban, újsorral lezárva.

    /dev/pgrpid
    Ezt a file-t olvasva a jelenlegi processz processz-csoport ID-jével tér vissza decimális alakban, újsorral lezárva.

    /dev/user
    Ezt a file-t olvasva egy újsorral lezárt rekorddal tér vissza. A mezôk space-szel vannak elválasztva. $1 az értéke a getuid(2) rendszerhívásnak, $2 az értéke a geteuid (2) rendszerhívásnak, $3 az értéke a getgid (2) rendszerhívásnak, és $4 az értéke a getegid (2) rendszerhívásnak. Ha vannak további mezôk, akkor azok a csoport ID-k, amivel a getgroups (2) visszatér. Többszörös csoportokat lehetséges, hogy nem minden rendszer támogat.

    /dev/stdin
    A standard bemenet.

    /dev/stdout
    A standard kimenet.

    /dev/stderr
    A standard hibakimenet.

    /dev/fd/ n
    A file az n . nyitott file leíróval van társítva.

    Ezek fôleg hibaüzenetként használhatók. Például:

    print "Elrontottad !" > "/dev/stderr"

    különben ezt kellene használni

    print "Elrontottad !" | "cat 1>&2"

    Ezek a filenevek használhatók a parancssorban az adatfileok megnevezésére.

    Numerikus függvények

    Az AWKnak a következô elôre definiált aritmetikai függvényei vannak:

    atan2( y , x )
    y/x arcustangens-ével tér vissza radiánban.

    cos( expr )
    a cosinusával tér vissza.

    exp( expr )
    az exponenciális függvény.

    int( expr )
    az egészrészt veszi.

    log( expr )
    a természetes alapú logaritmus függvény.

    rand()
    0 es 1 közti számmal tér vissza.

    sin( expr )
    a sinusával tér vissza.

    sqrt( expr )
    a négyzetgyök függvény.

    srand( expr )
    expr -t használja a véletlenszámgenerátor mint kezdôértéket. Ha nincs expr megadva, akkor a napi idôt fogja használni. A visszatérési érték a véletlenszámgenerátor elôzô kezdôértéke.

    Sztringkezelô függvények

    Az AWK a következô elôdefiniált sztringkezelô függvénykkel rendelkezik

    gsub(r, s, t)
    A t sztring minden olyan reszsztringjét,amely megfelel az reguláaris kifejezésnek az s sztringgel helyetesíti.Visszatérési értékként a helyetesítések számát adja vissza.Ha t nincs megadva,akkor az $0-t használja.

    index( s , t )
    A t sztring kezdôindexét az s sztringben,illetôleg 0-t ad vissza,ha a t nem fordul elô az s-ben

    length( s )
    Az s sztring,illetôleg az $0 (ha nincs megadva) hosszát adja vissza

    match( s , r )
    Visszaadja azt az s-beli poziciót,ahol az r reguláris kifejezéz elôfordul,illetôleg 0-t,ha nem fordúl elô az r az sztringben,valamint beállítja az RSTART és az RLENGTH értékét.

    split(s, a, r)
    Széttördeli az s sztringet az a tömbbe az r reguláris kifejezés alapján.Ha az r nincs megadva,akkor az FS-t használja. Az a tömbböt elôzôleg lenulláza.
    sprintf( fmt , expr-list )
    Az expr-list tartalmát kiírja az fmt-nek megfelelôen,és az eredményül kapott sztringgel tér vissza.

    sub(r, s, t)
    Úgyanaz,mint a gsub,de csak az elsô illeszkedô résztringet cseréli fel.

    substr(s, i, n)
    Az i-tôl kezdve n-karakter hosszan adja vissza az s-nek egy részét,illetôleg n hiányában az s maradékát.

    tolower( str )
    Az str sztring egy másolatát adja vissza,ahol a nagybetûk kisbetûkké lettek változtatva.A nem abc karaktereket nem változtatja.

    toupper( str )
    Az str sztring egy másolatát adja vissza,amelyben a nagybetûk a megfelelô kisbetûkkel lettek felcserélve,a nem abc karakterek változatlanok.

    Idôkezelô függvények

    Mivel az AWK programok egyik elsôdleges felhasználása a log file-ok kezelése,melyek keltezé idôrôl tartalmaznak információt,a GAWK a következô két függ vénnyel rendelkezik a keltezési idô leolvasására és formatálására

    systime()
    Az aktualis idôt adja vissza másodpercekben a kezdeti idôszámítástól kezdve.

    strftime(format, timestamp)
    formats timestamp according to the specification 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. See the specification for the strftime() function in ANSI C for the format conversions that are guaranteed to be available. A public-domain version of strftime (3) and a man page for it are shipped with gawk ; if that version was used to build gawk , then all of the conversions described in that man page are available to gawk.

    String Constants

    String constants in AWK are sequences of characters enclosed between double quotes ("). Within strings, certain "escape sequences" are recognized, as in C. These are:

    \\
    A literal backslash.

    \a
    The ``alert'' character; usually the ASCII BEL character.

    \b
    backspace.

    \f
    form-feed.

    \n
    new line.

    \r
    carriage return.

    \t
    horizontal tab.

    \v
    vertical tab.

    \x hex digits
    The character represented by the string of hexadecimal digits following the \x . As in ANSI C, all following hexadecimal digits are considered part of the escape sequence. (This feature should tell us something about language design by committee.) E.g., "\x1B" is the ASCII ESC (escape) character.

    \ ddd
    The character represented by the 1-, 2-, or 3-digit sequence of octal digits. E.g. "\033" is the ASCII ESC (escape) character.

    \ c
    The literal character c .

    The escape sequences may also be used inside constant regular expressions (e.g., "/[ \t\f\n\r\v]/" matches whitespace characters).

    FUNCTIONS

    Functions in AWK are defined as follows:

    function name(parameter list) { statements }

    Functions are executed when called from within the action parts of regular pattern-action statements. Actual parameters supplied in the function call are used to instantiate the formal parameters declared in the function. Arrays are passed by reference, other variables are passed by value.

    Since functions were not originally part of the AWK language, the provision for local variables is rather clumsy: They are declared as extra parameters in the parameter list. The convention is to separate local variables from real parameters by extra spaces in the parameter list. For example:

    function  f(p, q,     a, b) {	# a & b are local
    			..... }
    
    /abc/ { ... ; f(1, 2) ; ... }

    The left parenthesis in a function call is required to immediately follow the function name, without any intervening white space. This is to avoid a syntactic ambiguity with the concatenation operator. This restriction does not apply to the built-in functions listed above.

    Functions may call each other and may be recursive. Function parameters used as local variables are initialized to the null string and the number zero upon function invocation.

    The word func may be used in place of function .

    EXAMPLES

    Print and sort the login names of all users:
    
    BEGIN { FS = ":" } { print $1 | "sort" }
    Count lines in a file:
    { nlines++ } END { print nlines }
    Precede each line by its number in the file:
    { print FNR, $0 }
    Concatenate and line number (a variation on a theme):
    { print NR, $0 }

    SEE ALSO

    egrep (1), getpid (2), getppid (2), getpgrp (2), getuid (2), geteuid (2), getgid (2), getegid (2), getgroups (2)

    The AWK Programming Language , Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger, Addison-Wesley, 1988. ISBN 0-201-07981-X.

    The GAWK Manual , Edition 0.15, published by the Free Software Foundation, 1993.

    POSIX COMPATIBILITY

    A primary goal for gawk is compatibility with the POSIX standard, as well as with the latest version of UNIX awk . To this end, gawk incorporates the following user visible features which are not described in the AWK book, but are part of awk in System V Release 4, and are in the POSIX standard.

    The -v option for assigning variables before program execution starts is new. The book indicates that command line variable assignment happens when awk would otherwise open the argument as a file, which is after the BEGIN block is executed. However, in earlier implementations, when such an assignment appeared before any file names, the assignment would happen before the BEGIN block was run. Applications came to depend on this ``feature.'' When awk was changed to match its documentation, this option was added to accommodate applications that depended upon the old behavior. (This feature was agreed upon by both the AT&T and GNU developers.)

    The -W option for implementation specific features is from the POSIX standard.

    When processing arguments, gawk uses the special option ``--'' to signal the end of arguments. In compatibility mode, it will warn about, but otherwise ignore, undefined options. In normal operation, such arguments are passed on to the AWK program for it to process.

    The AWK book does not define the return value of srand() . The System V Release 4 version of UNIX awk (and the POSIX standard) has it return the seed it was using, to allow keeping track of random number sequences. Therefore srand() in gawk also returns its current seed.

    Other new features are: The use of multiple -f options (from MKS awk ); the ENVIRON array; the \a , and \v escape sequences (done originally in gawk and fed back into AT&T's); the tolower() and toupper() built-in functions (from AT&T); and the ANSI C conversion specifications in printf (done first in AT&T's version).

    GNU Kiterjesztések

     A Gawk-nak van néhány kiterjesztése a POSIX awk-ra . Ezek vannak leirva a következõ részben. Minden kiterjesztés leirását le lehet tiltani a gawk -W compat opció
    segitségével.

    A gawk következõ elemei nem használhatók a POSIX awk-val .

    A \x escape szekvencia.

    A systime() és a strftime() függvények.

    A különleges filenevek I/O átirányitásai nem lehetségesek.

    Az ARGIND és az ERRNO változók nem speciálisak.

    Az IGNORECASE változó és ennek következményei nem lehetségesek.

    A FIELDWIDTHS változó és a rögzitett szélességû mezõk.

    A via nevû file-ok keresési útvonala nem lesznek  feltüntetve a -f  opcióval.. Ezért az AWKPATH környezeti változó nincs specifikálva.

    A next file-t az aktuális input file-lal történõ folyamat megszekitására használják.

     A delete array-jel egy tömb teljes tartalmát kitörölhetjük.

    Az AWK könyv nem definiálja a close() függvény visszatérési értékét. A Gawk close() függvénye az fclose (3), vagy a  pclose (3) értékével tér vissza, illetve mikor egy filet vagy egy pipe-t bezár.

    Mikor a gawk-ot segitségül hivjuk a -W compat opcióval , és ha az fs argumentum -F opciója ``t'', akkor az FS a tab karakterre állitódik. Mivel ez elég ritka eset , ez nem az alapértelmezés. Ez akkor sem fordul elõ ,ha a -W posix specifikálva lett.

    Ha a gawk ellenõrzés céljából van leforditva , a következõ plusz opciók lesznek lehetségesek:

    -Wparsedebug

    --parsedebug
    Bekapcsolja a yacc (1) vagy a  bison (1) ellenõrõ kimenetet a program elemzése alatt. Ez az opció csak érdekesség azoknak akik a  gawk-ot  használják, és talán nincs is a gawk-ba forditva .

    HISTORICAL FEATURES

    There are two features of historical AWK implementations that gawk supports. First, it is possible to call the length() built-in function not only with no argument, but even without parentheses! Thus,

    a = length

    is the same as either of

    a = length()
    a = length($0)

    This feature is marked as ``deprecated'' in the POSIX standard, and gawk will issue a warning about its use if -W lint is specified on the command line.

    The other feature is the use of either the continue or the break statements outside the body of a while , for , or do loop. Traditional AWK implementations have treated such usage as equivalent to the next statement. Gawk will support this usage if -W compat has been specified.

    ENVIRONMENT VARIABLES

    If POSIXLY_CORRECT exists in the environment, then gawk behaves exactly as if --posix had been specified on the command line. If --lint has been specified, gawk will issue a warning message to this effect.

    BUGS

    The -F option is not necessary given the command line variable assignment feature; it remains only for backwards compatibility.

    If your system actually has support for /dev/fd and the associated /dev/stdin , /dev/stdout , and /dev/stderr files, you may get different output from gawk than you would get on a system without those files. When gawk interprets these files internally, it synchronizes output to the standard output with output to /dev/stdout , while on a system with those files, the output is actually to different open files. Caveat Emptor.

    VERSION INFORMATION

    This man page documents gawk , version 2.15.

    Starting with the 2.15 version of gawk , the -c , -V , -C , -D , -a , and -e options of the 2.11 version are no longer recognized. This fact will not even be documented in the manual page for the next major version.

    AUTHORS

    The original version of UNIX awk was designed and implemented by Alfred Aho, Peter Weinberger, and Brian Kernighan of AT&T Bell Labs. Brian Kernighan continues to maintain and enhance it.

    Paul Rubin and Jay Fenlason, of the Free Software Foundation, wrote gawk , to be compatible with the original version of awk distributed in Seventh Edition UNIX. John Woods contributed a number of bug fixes. David Trueman, with contributions from Arnold Robbins, made gawk compatible with the new version of UNIX awk . Arnold Robbins is the current maintainer.

    The initial DOS port was done by Conrad Kwok and Scott Garfinkle. Scott Deifik is the current DOS maintainer. Pat Rankin did the port to VMS, and Michal Jaegermann did the port to the Atari ST. The port to OS/2 was done by Kai Uwe Rommel, with contributions and help from Darrel Hankerson.

    BUG REPORTS

    If you find a bug in gawk , please send electronic mail to bug-gnu-utils@prep.ai.mit.edu , with a carbon copy to arnold@gnu.ai.mit.edu . Please include your operating system and its revision, the version of gawk , what C compiler you used to compile it, and a test program and data that are as small as possible for reproducing the problem.

    Before sending a bug report, please do two things. First, verify that you have the latest version of gawk . Many bugs (usually subtle ones) are fixed at each release, and if your's is out of date, the problem may already have been solved. Second, please read this man page and the reference manual carefully to be sure that what you think is a bug really is, instead of just a quirk in the language.

    ACKNOWLEDGEMENTS

    Brian Kernighan of Bell Labs provided valuable assistance during testing and debugging. We thank him.