Awk by example / Awk в примерах

→In defense of awk
0 В защиту awk
→Resources
0 Ресурсы
→Daniel Robbins
Daniel Robbins is the founder of the Gentoo community and creator of the Gentoo Linux operating system. Daniel resides in New Mexico with his wife Mary and two energetic daughters, and is founder and lead of Funtoo. Daniel has also written many technical articles for IBM developerWorks, Intel Developer Services and C/C++ Users Journal.
0 Дэниэль Роббинс
Дэниэль Роббинс — основатель сообщества Gentoo и создатель операционной системы Gentoo Linux. Дэниэль проживает в Нью-Мехико со свой женой Мэри и двумя энергичными дочерьми. Он также основатель и глава Funtoo, написал множество технических статей для IBM developerWorks, Intel Developer Services и C/C++ Users Journal.
→{
#skip header
if ( NR > 10 ) {
print "ok, now for the real information!"
}
}
0 {
#skip header
if ( NR > 10 ) {
print "ok, now for the real information!"
}
}
→(NR < 10 ) || (NR > 100) { print "We are on record number 1-9 or 101+" }
0 (NR < 10 ) || (NR > 100) { print "We are on record number 1-9 or 101+" }
→{
if ( NF > 2 ) {
print $1 " " $2 ":" $3
}
}
0 {
if ( NF > 2 ) {
print $1 " " $2 ":" $3
}
}
→NF == 3 { print "this particular record has three fields: " $0 }
0 NF == 3 { print "this particular record has three fields: " $0 }
→FS="foo[0-9][0-9][0-9]"
0 FS="foo[0-9][0-9][0-9]"
→FS="[[:space:]+]"
0 FS="[[:space:]+]"
→FS="\t+"
0 FS="\t+"
→{ print ($1^2)+1 }
0 { print ($1^2)+1 }
→2.01
0 2.01
→x="1.01"
# We just set x to contain the *string* "1.01"
x=x+1
# We just added one to a *string*
print x
# Incidentally, these are comments :)
0 x="1.01"
# We just set x to contain the *string* "1.01"
x=x+1
# We just added one to a *string*
print x
# Incidentally, these are comments :)
→BEGIN { x=0 }
/^$/ { x=x+1 }
END { print "I found " x " blank lines. :)" }
0 BEGIN { x=0 }
/^$/ { x=x+1 }
END { print "I found " x " blank lines. :)" }
→( $1 == "foo" ) && ( $2 == "bar" ) { print }
0 ( $1 == "foo" ) && ( $2 == "bar" ) { print }
→{
if ( $0 !~ /matchme/ ) {
print $1 $3 $4
}
}
0 {
if ( $0 !~ /matchme/ ) {
print $1 $3 $4
}
}
→! /matchme/ { print $1 $3 $4 }
0 ! /matchme/ { print $1 $3 $4 }
→{
if ( $1 == "foo" ) {
if ( $2 == "foo" ) {
print "uno"
} else {
print "one"
}
} else if ($1 == "bar" ) {
print "two"
} else {
print "three"
}
}
0 {
if ( $1 == "foo" ) {
if ( $2 == "foo" ) {
print "uno"
} else {
print "one"
}
} else if ($1 == "bar" ) {
print "two"
} else {
print "three"
}
}
→{
if ( $5 ~ /root/ ) {
print $3
}
}
0 {
if ( $5 ~ /root/ ) {
print $3
}
}
→$5 ~ /root/ { print $3 }
0 $5 ~ /root/ { print $3 }
Резюме
Пол:
мужчина
Родной язык:
русский
С нами:
с 14 ноября 2010 г. (5818 дней)
Не является членом клуба.
Деятельность:
178 версий перевода с общим рейтингом 9
3 комментария
Карма: 3 (оценок: 3)
Написать Daemon786 личное сообщение