The function of the GNU gawk tool is to format the lines in the specified file that match the specified pattern (pattern) with the specified action (action) syntax: gawk [Options] [program] [FILE-LIST]1, program format] Pattern {action} ' 2, $ $, ..., $n: Column 1th, ..., nth column 3, ~ (matches operator): contains $ Gawk ' ~/h/' cars4, relational operator: ==,<=,>=,!=,> < #dpkg –get-selections | Gawk ' $! = ' Install ' {print $} ' $ Gawk ' $ <= ' cars5, range operator:, $ Gawk '/volvo/,/bmw/' CARS6, BEGIN mode, end mode $ Gawk ' END {print NR, "Cars for Sale."} ' Cars7, $: Current line 8, length function $ Gawk ' {print length, $} ' cars | Sort-n9, NR (record number) variable $ Gawk ' length > (Print NR} ' cars$ gawk ' nr = = 2, nr = = 4 ' cars10, OFS variable: Output field delimiter (onput Field separator) BEGIN {OFS = "} { if ($ ~/ply/) $ = "Plymouth" if ($ ~/chev/) $ = "Chevrolet" Print }11, FS: input field delimiter (Input fields separator) $ cat Find_uid
BEGIN {FS = ":" SaveIt = 0}$3 > SaveIt {saveit = $3}end {print "Next available UID is" SaveIt + 1}
$ gawk-f Find_uid/etc/passwdnext available UID is 192
$ gawk-f: ' {print $} ' file; The-f option is used to re-assign FS on the command line
$ gawk-f[:] ' {print $} ' file//Use multiple separators: space, colon: and TAB12, printf function begin { printf "%-10s%-8s%2d%5d $%8.2f", $, $, $, $4, $ }13, redirected output $ cat redirect_out
/chevy/{print > "Chevfile"}
/ford/{print > "Fordfile"}
END {print "Done."}
$ gawk-f redirect_out cars14, IF...ELSE control structure $ cat Price_range
{ if ($ <=) $ = "inexpensive" else if (< $ && $ < 10000) $ = "Please ask" else if (10000 <= $) $ = "expensive" printf "%-10s%-8s%2d%5d%-12s", $, $, $, $4, $ }15, Getline reads a row, and the pointer to gawk points to the next line (nr increment). If the variable is not taken: The row pointer changes immediately, NR increments, $0-$n change, if the variable: row pointer does not change within {}, nr increments, $0-$n does not change
$ cat G4 { Print NR, "$ A:", $ Getline AA Print NR, "AA:", AA }
$ gawk-f G4 < Alpha
1 $0:aaaaaaaaa
2 AA:BBBBBBBBB
3 $0:CCCCCCCCC
4 Aa:ddddddddd16, other gawk |& equivalent to bash's pipeline |gawk can get the file information from the network gawk variable assignment, the reference variable is not $, direct reference, unlike bash.
=-=-=-=-=
Powered by Blogilo
The use of gawk