awk
DESCRIPTION
awk in terminal, linuxTRANSCRIPT
-
-
e-mail:
?
UnixForum Linux
( )
.. mobi-sklad.com
.. .videonabludenie.mediapalace.ru
- .
" Linux Documentat ion Project"
linux: awk: Learning Linux Commands: awk : Rares Aioanei : 24 2011 : . : 22 2012 .1. , awk - , . . , . Aho,Weinberger Kernighan (, Brian Kernighan), , 1977 . C, awk. Linux , , , , , , . Arnold Robbins awk.
2. awk?awk - / . awk Larry Wall, Perl. awk sed. awk, Perl, . sed, awk , , . awk . Debian , awk , , aptitude. :$ dpkg -l | awk ' {print $2} ' > installed
, rpm's -qa, , . , dpkg -l , , .
3. , , awk, , - : awk 'condition { action }'. , , , , vim, (, grep, , , , ), :$ dpkg -l | awk ' /'vim'/ {print $2} '
, "vim" . , awk - . "vim" "lib", 1300 . , , awk . , , . , awk. , , GNU awk ( , ). - , bash, ksh sh, (t)csh.
4.
awk ' {print $1,$3} '
, stdin
awk ' {print $0} '
, stdin
,
linux: awk 3/21/14
http://rus-linux.net/MyLDP/consol/awk.html 1 / 1
-
awk ' /'pattern'/ {print $2} ' ,
"pattern",
stdin
awk -f script.awk inputfile
sed, awk -f
, ,
.
awk ' program ' inputfileprogram,
inputfile
awk "BEGIN { print \"Hello, world!!\" }"
"Hello, world" awk
awk '{ print }' ,
, EOF
#! /bin/awk -fBEGIN { print "Hello, world!" }
awk "Hello, world!"(
chmod )
# This is a program that prints \"Hello, world!"# and exits
awk
awk -F "" 'program' files
null,
awk -F "regex" 'program' files
awk '{ if (length($0) > max) max = \length($0) }
END { print max }' inputfile
awk 'length($0) > 80' inputfile
80
awk 'NF > 0' data
,
(NF Number of Fie lds)
awk 'BEGIN { for (i = 1; i
-
.
awk '$1 ~/J/' inputfile
,
j.
awk '$1 ~!/J/' inputfile
,
j.
awk 'BEGIN { print "He said \"hi!\" \to her." }'
awk.
echo aaaabcd | awk '{ sub(/a+/, \ ""); print }' "bcd"
awk '{ $2 = $2 - 10; print $0 }' inventory
inventory
,
10.
awk '{ $6 = ($5 + $4 + $3 + $2); print \ $6' inventory
inventory,
,
.
echo a b c d | awk '{ OFS = ":"; $2 = ""> print $0; print NF }'
OFS - OutputField Separator(
)
"a::c:d" "4",
,
,
.
echo a b c d | awk '{ OFS = ":"; \$2 = ""; $6 = "new"
> print $0; print NF }'
; ,
$4()
$6() ( $5),
"a::c:d::new""6".
echo a b c d e f | awk '\{ print "NF =", NF;> NF = 3; print $0 }'
()
.
FS=[ ]
.
echo ' a b c d ' | awk 'BEGIN { FS = \"[ \t\n]+" }
> { print $2 }'
"a".
awk -n '/RE/{p;q;}' file.txt
.
awk -F\\\\ '...' inputfiles ...
\\
BEGIN { RS = "" ; FS = "\n" }{
print "Name is:", $1print "Address is:", $2
print "City and State are:", $3
"John Doe1234 Unknown
Ave.Doeville , MA",
linux: awk 3/21/14
http://rus-linux.net/MyLDP/consol/awk.html 3 / 1
-
print ""}
,
.
awk 'BEGIN { OFS = ";"; ORS = "\n\n" }> { print $1, $2 }' inputfile
,
:
"fie ld1:fie ld2 fie ld3;fie ld4
...;..."
-
,
- ";".
awk 'BEGIN {> OFMT = "%.0f" # print numbers as \
integers (rounds)> print 17.23, 17.54 }'
17
18 ,
(OutputForMaT)
.awk 'BEGIN {
> msg = "Dont Panic!"> printf "%s\n", msg
>} '
printf , C.
awk '{ printf "%-10s %s\n", $1, \$2 }' inputfile
10,
,
.
awk '{ print $2 > "phone-list" }' \inputfile
,
"phone-
list".
awk '{ print $1 > "names.unsorted" command = "sort -r > names.sorted" print $1 | command }' inputfile
,
$1, ,
.
awk 'BEGIN { printf "%d, %d, %d\n", 011, 11, \0x11 }'
Will print 9, 11, 17if (/foo/ || /bar/) print "Found!"
foo bar.
awk '{ sum = $2 + $3 + $4 ; avg = sum / 3> print $1, avg }' grades
( C)
awk '{ print "The square root of", \$1, "is", sqrt($1) }'
2The square root of 2 is 1.41421
7The square root of 7 is 2.64575
awk '$1 == "start", $1 == "stop"' inputfile
start stop.
awk '> BEGIN { print "Analysis of \"foo\"" }
> /foo/ { ++n }> END { print "\"foo\" appears", n,\
"times." }' inputfile
BEGIN END ,
.echo -n "Enter search pattern: "
read patternawk "/$pattern/ "'{ nmatches++ }
END { print nmatches, "found" }' inputfileSearch using shellif (x % 2 == 0)print "x is even"
.awk, C,
?:.
linux: awk 3/21/14
http://rus-linux.net/MyLDP/consol/awk.html 4 / 1
-
elseprint "x is odd"awk '{ i = 1
while (i