awk(1)


awk -- Ñ╤Ñ┐í╝Ñ≤Ñ╣Ñ¡ÑπÑ≤ñ¬ñΦñ╙╜Φ═²╕└╕∞

╖┴╝░

 
   awk  [-f progfile | 'prog']  [-Ffieldsep] [-v var=value] [file . . .] 

╡í╟╜└Γ╠└

awk ñ╧│╞╞■╬╧ file ñ≥Ñ╣Ñ¡ÑπÑ≤ñ╖ñ╞íóprog ñ╦╗╪─Ωñ╡ñ∞ñ┐Ñ╤Ñ┐í╝Ñ≤╜╕╣τñ╬ñññ║ñ∞ñ½ñ╦░∞├╫ñ╣ñδ╣╘ñ≥├╡ñ╖ñ▐ñ╣íúprog ╩╕╗·╬≤ñ╧íóÑ╖ѺÑδñ½ñΘ╩▌╕εñ╣ñδñ┐ñßñ╦├▒░∞░·═╤╔Σ(')ñ╟░╧ñα╔¼═╫ñ¼ñóñΩñ▐ñ╣íúÑ╤Ñ┐í╝Ñ≤ñ╧íó│╚─Ñ└╡╡¼╔╜╕╜(grep(1) ╗▓╛╚)ñ╚┤╪╖╕╝░ñ≥╟ñ░╒ñ╦╧└═²╖δ╣τñ╖ñ┐ñΓñ╬ñ╟ñ╣íú│╞Ñ╤Ñ┐í╝Ñ≤ñ≥ prog ñ╦╩▌═¡ñ╖íófile ñ╬ 1 ╣╘ñ¼Ñ╤Ñ┐í╝Ñ≤ñ╦░∞├╫ñ╖ñ┐ñ╚ñ¡ñ╦╝┬╣╘ñ╡ñ∞ñδÑóÑ»Ñ╖ÑτÑ≤ñ≥╗╪─Ωñ╟ñ¡ñ▐ñ╣íúÑ╤Ñ┐í╝Ñ≤╜╕╣τñ╧íóprog ñ╚ñ╖ñ╞─╛└▄╡¡╜╥ñ╣ñδñ½íóñ▐ñ┐ñ╧ -f progfile ñ╟╗╪─Ωñ╡ñ∞ñ┐Ñ╒ÑíÑñÑδñ╦╡¡╜╥ñ╟ñ¡ñ▐ñ╣íúÑ╒ÑíÑñÑδñ╧╗╪─Ωñ╬╜τñ╦╞╔ñ▀╣■ñ▐ñ∞ñ▐ñ╣íúÑ╒ÑíÑñÑδñ╬╗╪─Ωñ¼ñ╩ññ╛∞╣τíó╔╕╜α╞■╬╧ñ½ñΘ╞╔ñ▀╣■ñ▐ñ∞ñ▐ñ╣íúÑ╒ÑíÑñÑδ╠╛ - ñ╧╔╕╜α╞■╬╧ñ≥░╒╠úñ╖ñ▐ñ╣íú

awk ñ╧íóÑ╤Ñ┐í╝Ñ≤ÑóÑ»Ñ╖ÑτÑ≤╩╕ñ╚├φ╝ßñ╦ñóñδ╩Σ╜⌡Ñ│í╝Ñ╔Ñ╗Ñ├Ñ╚╩╕╗·ñ≥╜Φ═²ñ╖íó╩Σ╜⌡Ñ│í╝Ñ╔Ñ╗Ñ├Ñ╚╩╕╗·ñ≥┤─╢¡╩╤┐⌠ LC_CTYPE ñ╦╗╪─Ωñ╡ñ∞ñ┐ÑφÑ▒í╝Ñδñ╦┤≡ñ┼ñññ╞íóÑ╒Ñúí╝ÑδÑ╔╩¼╬Ñ╡¡╣µñ╚ñ╖ñ╞╟º╝▒ñ╖ñ▐ñ╣(environ(5) ñ╬ LANG ╗▓╛╚)íúgrep(1) ñ╟└Γ╠└ñ╖ñ┐ñΦñªñ╦íó└╡╡¼╔╜╕╜ñ╟ñ╧Ñ╤Ñ┐í╝Ñ≤╕í║≈ñ¼Ñ╨ÑñÑ╚ñ╟ñ╧ñ╩ñ»íó╩╕╗·ñ╦┬╨ñ╖ñ╞╝┬╣╘ñ╡ñ∞ñ▐ñ╣íú

│╞╣╘ñ╚ñ╣ñ┘ñ╞ñ╬Ñ╤Ñ┐í╝Ñ≤ÑóÑ»Ñ╖ÑτÑ≤╩╕ñ╬Ñ╤Ñ┐í╝Ñ≤╔⌠ñ¼╚µ│╙ñ╡ñ∞ñ▐ñ╣íú░∞├╫ñ╖ñ┐Ñ╤Ñ┐í╝Ñ≤ñ┤ñ╚ñ╦íó┬╨▒■ñ╣ñδÑóÑ»Ñ╖ÑτÑ≤ñ¼╝┬╣╘ñ╡ñ∞ñ▐ñ╣íúvar=value ñ╬╖┴╝░ñ╬ file ñ╧íóÑ╒ÑíÑñÑδ╠╛ñ╟ñ╧ñ╩ñ»┬σ╞■╝░ñ╚ñ╖ñ╞░╖ñ∩ñ∞íóÑ╒ÑíÑñÑδ╠╛ñ╟ñóñ∞ñ╨Ѭí╝Ñ╫Ñ≤ñ╡ñ∞ñ┐╗■┼└ñ╟╝┬╣╘ñ╡ñ∞ñ▐ñ╣íúvar=value ñ╬┴░ñ╬ -v ѬÑ╫Ñ╖ÑτÑ≤ñ╧íóprog ñ¼╝┬╣╘ñ╡ñ∞ñδ┴░ñ╦╣╘ñ∩ñ∞ñδ┬σ╞■ñ╟ñ╣íú-v ѬÑ╫Ñ╖ÑτÑ≤ñ╧ñññ»ñ─ñ╟ñΓ╗╪─Ωñ╟ñ¡ñ▐ñ╣íú

╞■╬╧╣╘ñ╧íó╢⌡╟≥Ñ╣Ñ┌í╝Ñ╣ñ╟╢Φ└┌ñΘñ∞ñ┐Ñ╒Ñúí╝ÑδÑ╔ñ½ñΘ╣╜└«ñ╡ñ∞ñ▐ñ╣íú(ñ│ñ∞ñ¼╛╩╬¼╗■ñ╬▓≥╝ßñ╟ñ╣ñ¼íó▓╝╡¡ñ╦╝¿ñ╣ñΦñªñ╦ FS ñ▐ñ┐ñ╧ -Ffieldsep ѬÑ╫Ñ╖ÑτÑ≤ñ≥╗╚═╤ñ╖ñ╞╩╤╣╣ñ╟ñ¡ñ▐ñ╣íú) Ñ╒Ñúí╝ÑδÑ╔ñ╧ $1íó$2íó... ñ╚╔╜ñ╖íó$0 ñ╧╣╘┴┤┬╬ñ≥░╒╠úñ╖ñ▐ñ╣íú

Ñ╤Ñ┐í╝Ñ≤ÑóÑ»Ñ╖ÑτÑ≤╩╕ñ╬╖┴╝░ñ╧▓╝╡¡ñ╬ñ╚ñ¬ñΩñ╟ñ╣íú

 
   pattern { action } 

Ñ╤Ñ┐í╝Ñ≤ñóñδñññ╧ÑóÑ»Ñ╖ÑτÑ≤ñ╬ñ╔ñ┴ñΘñ½ñ¼╛╩╬¼ñ╟ñ¡ñ▐ñ╣íúÑóÑ»Ñ╖ÑτÑ≤ñ≥╛╩╬¼ñ╣ñδñ╚íó░∞├╫ñ╣ñδ╣╘ñ¼╜╨╬╧ñ╡ñ∞ñ▐ñ╣íúÑ╤Ñ┐í╝Ñ≤ñ≥╛╩╬¼ñ╣ñδñ╚íóñ╜ñ╬ÑóÑ»Ñ╖ÑτÑ≤ñ¼│╞╞■╬╧╣╘ñ╟╝┬╣╘ñ╡ñ∞ñ▐ñ╣íúÑ╤Ñ┐í╝Ñ≤-ÑóÑ»Ñ╖ÑτÑ≤╩╕ñ╧íó╔ⁿ╡ó▓■╣╘ñóñδñññ╧Ñ╗Ñ▀Ñ│ÑφÑ≤ñ╟╢Φ└┌ñΘñ∞ñ▐ñ╣íú

┴░╜╥ñ╬ñΦñªñ╦íóÑ╤Ñ┐í╝Ñ≤ñ╧│╚─Ñ└╡╡¼╔╜╕╜ñ╚┤╪╖╕╝░ñ≥╟ñ░╒ñ╦╧└═²╖δ╣τ(``!''íó``||''íó&& ñ¬ñΦñ╙│τ╕╠)ñ╖ñ┐ñΓñ╬ñ╟ñ╣íú┤╪╖╕╝░ñ╧íó▓╝╡¡ñ╬ñªñ┴ñ╬ñññ║ñ∞ñ½ñ╟ñ╣íú

 
   expression relop expression 
   expression matchop regular_expression 
   expression in array-name 
   (expression,expression, 
   ... 
  ) in array-name 

ñ│ñ│ñ╟íórelop ñ╧ C ╕└╕∞ñ╬ 6 ñ─ñ╬┤╪╖╕▒Θ╗╗╗╥ñ╬ 1 ñ─ñ╟ñóñΩíómatchop ñ╧``~''(┤▐ñαñ╚ñ¡)ñ▐ñ┐ñ╧``!~''(┤▐ñ▐ñ╩ñññ╚ñ¡)ñ╬ñññ║ñ∞ñ½ñ╟ñ╣íúexpression ñ╧╗╗╜╤╝░íó┤╪╖╕╝░íó╞├╩╠╝░

 
   var in array 

ñ▐ñ┐ñ╧ñ│ñ∞ñΘñ≥╧└═²╖δ╣τñ╖ñ┐ñΓñ╬ñ╟ñ╣íú

│╚─Ñ└╡╡¼╔╜╕╜ñ╧Ñ╣ÑΘÑ├Ñ╖Ñσñ╟░╧ñ▐ñ╩ñ▒ñ∞ñ╨ñ╩ñΩñ▐ñ╗ñ≤íúÑ╤Ñ┐í╝Ñ≤╞Γñ╬╞╚╬⌐ñ╖ñ┐└╡╡¼╔╜╕╜ñ╧╣╘┴┤┬╬ñ╦┼¼═╤ñ╡ñ∞ñ▐ñ╣íú│╚─Ñ└╡╡¼╔╜╕╜ñ≥┤╪╖╕╝░ñ╦╞■ñ∞ñδñ│ñ╚ñΓñ╟ñ¡ñ▐ñ╣íúÑ╤Ñ┐í╝Ñ≤ñ╧íó2 ñ─ñ╬Ñ╤Ñ┐í╝Ñ≤ñ≥Ñ│Ñ▐Ñ≤Ñ╔ñ╟╢Φ└┌ñ├ñ╞╡¡╜╥ñ╣ñδñ│ñ╚ñΓñ╟ñ¡ñ▐ñ╣íúñ│ñ╬╛∞╣τíóÑóÑ»Ñ╖ÑτÑ≤ñ╧║╟╜Θñ╬Ñ╤Ñ┐í╝Ñ≤ñ╚╝íñ╬Ñ╤Ñ┐í╝Ñ≤ñ╬┤╓ñ╬ñ╣ñ┘ñ╞ñ╬╣╘ñ╟╝┬╣╘ñ╡ñ∞ñ▐ñ╣íú

╞├╝∞Ñ╤Ñ┐í╝Ñ≤ñ╬ BEGIN ñ╚ END ñ≥╗╚═╤ñ╖ñ╞íó║╟╜Θñ╬╞■╬╧╣╘ñ¼╞╔ñ▀╣■ñ▐ñ∞ñδ┴░ñ╚║╟╕σñ╬╞■╬╧╣╘ñ¼╞╔ñ▀╣■ñ▐ñ∞ñ┐╕σñ╟└⌐╕µñ╟ñ¡ñ▐ñ╣íúñ│ñ∞ñΘñ╬Ñ¡í╝Ñ∩í╝Ñ╔ñ╧┬╛ñ╬Ñ╤Ñ┐í╝Ñ≤ñ╚ñ╧┴╚╣τñ╗ñ╟ñ¡ñ▐ñ╗ñ≤íú

│╚─Ñ└╡╡¼╔╜╕╜ñ╧íó-F fieldsep ѬÑ╫Ñ╖ÑτÑ≤ñ≥╗╚═╤ñ╣ñδñ½íóñ▐ñ┐ñ╧╔╜╕╜ñ≥┴╚ñ▀╣■ñ▀╩╤┐⌠ FS ñ╦│ΣñΩ┼÷ñ╞ñδñ│ñ╚ñ╦ñΦñΩíóÑ╒Ñúí╝ÑδÑ╔ñ≥╢Φ└┌ñδñ╬ñ╦╗╚═╤ñ╟ñ¡ñ▐ñ╣íú╛╩╬¼├═ñ╟ñ╧└Φ╞¼ñ╬╢⌡╟≥ñ╧╠╡╗δñ╡ñ∞íóÑ╒Ñúí╝ÑδÑ╔ñ╧╢⌡╟≥ñ¬ñΦñ╙(ñ▐ñ┐ñ╧)Ñ┐Ñ╓ñ╦ñΦñΩ╢Φ└┌ñΘñ∞ñ▐ñ╣íúñ┐ñ└ñ╖ FS ñ╦├═ñ¼│ΣñΩ┼÷ñ╞ñΘñ∞ñ╞ñññδ╛∞╣τñ╧íó└Φ╞¼ñ╬╢⌡╟≥ñ╧╠╡╗δñ╡ñ∞ñ▐ñ╗ñ≤íú

┬╛ñ╬┴╚ñ▀╣■ñ▀╩╤┐⌠ñ≥íó╝íñ╦╝¿ñ╖ñ▐ñ╣íú

ARGC
Ñ│Ñ▐Ñ≤Ñ╔ÑΘÑñÑ≤░·ñ¡┐⌠ñ╬┐⌠

ARGV
Ñ│Ñ▐Ñ≤Ñ╔ÑΘÑñÑ≤░·ñ¡┐⌠ñ╬╟█╬≤

CONVFMT
└░┐⌠░╩│░ñ╬┐⌠├═ñ╬╩╤┤╣╖┴╝░íúsprintf ┴╚ñ▀╣■ñ▀┤╪┐⌠ñ╬└Γ╠└ñ≥╗▓╛╚ñ╖ñ╞ñ»ñ└ñ╡ññíú

└░┐⌠ñ╬├═ñ╚└╡│╬ñ╦┼∙ñ╖ññ┐⌠├═ñ╧íósprintf ┴╚ñ▀╣■ñ▀┤╪┐⌠ñ╬ fmt Ñ╤ÑΘÑßí╝Ñ┐ñ╦╩╕╗·╬≤ %d ñ≥╗╪─Ωñ╖ñ┐╕╞ñ╙╜╨ñ╖ñ╦┴Ω┼÷ñ╣ñδ╩╕╗·╬≤ñ╚íó░∞╚╓╠▄ñ╟═ú░∞ñ╬ expr Ñ╤ÑΘÑßí╝Ñ┐ñ╚ñ╖ñ╞╩╤┤╣ñ╡ñ∞ñδ┐⌠├═ñ╦╩╤┤╣ñ╡ñ∞ñ▐ñ╣íúñ│ñ∞░╩│░ñ╬┐⌠├═ñ╧íósprintf ┴╚ñ▀╣■ñ▀┤╪┐⌠ñ╬ fmt Ñ╤ÑΘÑßí╝Ñ┐ñ╦╩╤┐⌠ CONVFMT ñ≥╗╪─Ωñ╖ñ┐╕╞ñ╙╜╨ñ╖ñ╦┴Ω┼÷ñ╣ñδ╩╕╗·╬≤ñ╚íó░∞╚╓╠▄ñ╟═ú░∞ñ╬ expr Ñ╤ÑΘÑßí╝Ñ┐ñ╚ñ╖ñ╞╩╤┤╣ñ╡ñ∞ñδ┐⌠├═ñ╦╩╤┤╣ñ╡ñ∞ñ▐ñ╣íú

ENVIRON
┤─╢¡╩╤┐⌠ñ╬╟█╬≤íó┼║╗·ñ╧╠╛┴░

FILENAME
╕╜║▀ñ╬╞■╬╧Ñ╒ÑíÑñÑδ╠╛

FNR
╕╜║▀ñ╬Ñ╒ÑíÑñÑδ╞Γñ╬Ñ∞Ñ│í╝Ñ╔ñ╬╜τ╜°┐⌠

FS
╞■╬╧Ñ╒Ñúí╝ÑδÑ╔╩¼╬Ñ╡¡╣µ└╡╡¼╔╜╕╜(╛╩╬¼├═ñ╧╢⌡╟≥ñ╚Ñ┐Ñ╓)

NF
╕╜║▀ñ╬Ñ∞Ñ│í╝Ñ╔╞Γñ╬Ñ╒Ñúí╝ÑδÑ╔┐⌠

NR
╕╜║▀ñ╬Ñ∞Ñ│í╝Ñ╔╞Γñ╬╜τ╜°┐⌠

OFMT
┐⌠╗·ñ╬╜╨╬╧╖┴╝░(╛╩╬¼├═ñ╧ %.6g)

OFS
╜╨╬╧Ñ╒Ñúí╝ÑδÑ╔╩¼╬Ñ╡¡╣µ(╛╩╬¼├═ñ╧╢⌡╟≥)

ORS
╜╨╬╧Ñ∞Ñ│í╝Ñ╔╩¼╬Ñ╡¡╣µ(╛╩╬¼├═ñ╧╔ⁿ╡ó▓■╣╘)

RS
╞■╬╧Ñ∞Ñ│í╝Ñ╔╩¼╬Ñ╡¡╣µ(╛╩╬¼├═ñ╧╔ⁿ╡ó▓■╣╘)

SUBSEP
╩ú┐⌠ñ╬┼║╗·ñ≥╩¼╬Ññ╖ñ▐ñ╣(╛╩╬¼├═ñ╧ 034)íú

-F ѬÑ╫Ñ╖ÑτÑ≤íóñ▐ñ┐ñ╧ OFSíóORS ñ¬ñΦñ╙ FS ╩╤┐⌠ñ╟╗╪─Ωñ╖ñ┐Ñ╒Ñúí╝ÑδÑ╔╩¼╬Ñ╡¡╣µñ╧íó╩Σ╜⌡Ñ│í╝Ñ╔Ñ╗Ñ├Ñ╚ñ╬╩╕╗·ñ╟ñΓñ½ñ▐ñññ▐ñ╗ñ≤íú

ÑóÑ»Ñ╖ÑτÑ≤ñ╧╩╕ñ≥╩┬ñ┘ñ┐ñΓñ╬ñ╟ñ╣íú╩╕ñ╧╝íñ╬ñññ║ñ∞ñ½ñ╟ñ╣íú

 
   if (expression) statement [else statement] 
   while (expression) statement 
   do statement while (expression) 
   for (expression ; expression ; expression) statement 
   for (var in array) statement 
   delete array[subscript] #delete an array element 
   break 
   continue 
   { [statement] ... } 
   expression	# commonly variable = expression 
   print [expression-list] [>expression] 
   printf format [, expression-list] [>expression] 
   next		# skip remaining patterns on this input line 
   exit [expr]	# skip the rest of the input; exit status is expr 
   return [expr] 

╩╕ñ╧Ñ╗Ñ▀Ñ│ÑφÑ≤íó╔ⁿ╡ó▓■╣╘íóñ▐ñ┐ñ╧▒ª│τ╕╠ñ╟╜¬╬╗ñ╖ñ▐ñ╣íú╢⌡ñ╬╝░ÑΩÑ╣Ñ╚ñ╧╣╘┴┤┬╬ñ≥░╒╠úñ╖ñ▐ñ╣íú╝░ñ╦ñ╧╩╕╗·╬≤ñΣ┐⌠├═ñ¼┼¼╡╣┴╚ñ▀╣■ñ▐ñ∞ñ╞ñ¬ñΩíó▒Θ╗╗╗╥ñ╬``+''íó``-''íó``ASTERISK OPERATOR''íó``/''íó``%''íó``^''ñ¬ñΦñ╙╧ó╖δ╡¡╣µ(Ñ╓ÑΘÑ≤Ñ»ñ╟╝¿ñ╣)ñ≥╗╚═╤ñ╖ñ╞║ε└«ñ╡ñ∞ñ▐ñ╣íú╝░ñ╦ñ╧ C ñ╬▒Θ╗╗╗╥ñ╟ñóñδ``++''íó``--''íó``+=''íó``-=''íó``ASTERISK OPERATOR=''íó``/=''íó``%=''íó``^= >''íó``>=''íó``<''íó``<=''íó``==''íó``!=''íó``?:''ñΓ╗╚═╤ñ╟ñ¡ñ▐ñ╣íú╩╤┐⌠ñ╚ñ╖ñ╞ñ╧íóÑ╣ѽÑΘíó╟█╬≤═╫┴╟ (x[i] ñ╟╝¿ñ╣)íóñ▐ñ┐ñ╧Ñ╒Ñúí╝ÑδÑ╔ñ¼▓─╟╜ñ╟ñ╣íú╩╤┐⌠ñ╦ñ╧Ñ╠Ñδ╩╕╗·╬≤ñ¼╜Θ┤ⁿ└▀─Ωñ╡ñ∞ñ▐ñ╣íú╟█╬≤ñ╬Ñ╡Ñ╓Ñ╣Ñ»ÑΩÑ╫Ñ╚ñ╧╔¼ñ║ñ╖ñΓ┐⌠├═ñ╟ñ╩ñ»ñ╞ñΓñΦñ»íó╟ñ░╒ñ╬╩╕╗·╬≤ñ╟ñΓñ½ñ▐ñññ▐ñ╗ñ≤íúñ│ñ╬ñ┐ñßíó╧ó┴█╡¡▓▒ñ╬╖┴╝░ñ¼▓─╟╜ñ╟ñ╣íú[i, j, k] ñ╬ñΦñªñ╩╩ú┐⌠ñ╬Ñ╡Ñ╓Ñ╣Ñ»ÑΩÑ╫Ñ╚ñΓ▓─╟╜ñ╟ñ╣íú═╫┴╟ñ╧íóSUBSEP ñ╬├═ñ╦ñΦñΩ╧ó╖δñóñδñññ╧╢Φ└┌ñΘñ∞ñ▐ñ╣íú╩╕╗·╬≤─Ω┐⌠ñ╧░·═╤╔Σ(``""'')ñ╟░╧ñ▀ñ▐ñ╣íúñ│ñ╬ñ╚ñ¡╔ß─╠ñ╬ C ñ╬Ñ¿Ñ╣Ñ▒í╝Ñ╫ñ¼╟º╝▒ñ╡ñ∞ñ▐ñ╣íú

print ╩╕ñ╧íó░·ñ¡┐⌠ñ≥╕╜║▀ñ╬╜╨╬╧Ñ╒Ñúí╝ÑδÑ╔╩¼╬Ñ╡¡╣µñ╟╢Φ└┌ñΩíó╜╨╬╧Ñ∞Ñ│í╝Ñ╔╩¼╬Ñ╡¡╣µñ≥║╟╕σñ╦ñ─ñ▒ñ╞íó╔╕╜α╜╨╬╧ñ╦(>expression ñ¼ñóñδ╛∞╣τñ╧Ñ╒ÑíÑñÑδñ╦íó| cmd ñ¼ñóñδ╛∞╣τñ╧Ñ╤ÑñÑ╫ñ╦)╜╨╬╧ñ╖ñ▐ñ╣íúprintf ╩╕ñ╧íó╖┴╝░(fprintf(3S) ╗▓╛╚)ñ╦┤≡ñ┼ñññ╞╝░ÑΩÑ╣Ñ╚ñ≥Ñ╒Ñ⌐í╝Ñ▐Ñ├Ñ╚ñ╖ñ▐ñ╣íú┴╚╣■ñ▀┤╪┐⌠ close (expr) ñ╧íóÑ╒ÑíÑñÑδñ▐ñ┐ñ╧ expr Ñ╤ÑñÑ╫ñ≥Ñ»Ñφí╝Ñ║ñ╖ñ▐ñ╣íú

┐⌠│╪┤╪┐⌠ atan2íócosíóexpíólogíósiníósqrt ñ╧íó┴╚╣■ñ▀┤╪┐⌠ñ╟ñ╣íú

┬╛ñ╬┴╚ñ▀╣■ñ▀┤╪┐⌠ñ≥╝íñ╦╝¿ñ╖ñ▐ñ╣íú

gsub(for, repl, in)
sub (░╩▓╝╗▓╛╚) ñ╚╞▒══ñ╩╡í╟╜ñ≥╗²ñ┴ñ▐ñ╣ñ¼íó╧ó┬│ñ╣ñδ└╡╡¼╔╜╕╜ñ≥├╓ñ¡┤╣ñ¿ñδ┼└ñ╟░█ñ╩ñΩñ▐ñ╣(ed ñ╬ global substitute Ñ│Ñ▐Ñ≤Ñ╔ñ╚╞▒══)íú

index(s, t)
╩╕╗·╬≤ t ñ¼║╟╜Θñ╦╜╨╕╜ñ╖ñ┐╩╕╗·╬≤ s ╞Γñ╬░╠├╓ñ≥╩╓ñ╖ñ▐ñ╣íú╜╨╕╜ñ╖ñ╩ñ▒ñ∞ñ╨ 0 ñ≥╩╓ñ╖ñ▐ñ╣íú

int
└░┐⌠├═ñ╦└┌ñΩ╝╬ñ╞ñ▐ñ╣íú

length(s)
╩╕╗·╬≤ñ╬░·ñ¡┐⌠ñ╬Ñ╨ÑñÑ╚─╣íóñóñδñññ╧░·ñ¡┐⌠ñ¼ñ╩ñ▒ñ∞ñ╨1╣╘┴┤╔⌠ñ╬Ñ╨ÑñÑ╚─╣ñ≥╩╓ñ╖ñ▐ñ╣íú

match(s, re)
└╡╡¼╔╜╕╜ re ñ¼╜╨╕╜ñ╖ñ┐╩╕╗·╬≤ s ╞Γñ╬░╠├╓ñ≥╩╓ñ╖ñ▐ñ╣íú╜╨╕╜ñ╖ñ╩ññ╛∞╣τñ╧ 0 ñ≥╩╓ñ╖ñ▐ñ╣íúRSTART ñ¼│½╗╧░╠├╓(╠ßñΩ├═ñ╚╞▒ñ╕)ñ╦└▀─Ωñ╡ñ∞íóRLENGTH ñ╧░∞├╫ñ╖ñ┐╩╕╗·╬≤ñ╬─╣ñ╡ñ╦└▀─Ωñ╡ñ∞ñ▐ñ╣íú

rand
(0, 1) ñ╬═≡┐⌠ñ╟ñ╣íú

split(s, a, fs)
╩╕╗·╬≤ s ñ≥╟█╬≤═╫┴╟ a[1]íóa[2] ...íóa[n] ñ╦╩¼│Σñ╖íón ñ≥╩╓ñ╖ñ▐ñ╣íú╩¼│Σñ╧└╡╡¼╔╜╕╜ fsíóñóñδñññ╧ fs ñ¼═┐ñ¿ñΘñ∞ñ╩ññ╛∞╣τñ╧Ñ╒Ñúí╝ÑδÑ╔╩¼╬Ñ╡¡╣µ FS ñ╟╣╘ñ╩ñ∩ñ∞ñ▐ñ╣íú

srand
rand ñ╬Ñ╖í╝Ñ╔ñ≥└▀─Ωñ╖íó░╩┴░ñ╬Ñ╖í╝Ñ╔ñ≥╠ßñ╖ñ▐ñ╣íú

sprintf(fmt, expr, expr,...)
fmt ñ╟═┐ñ¿ñΘñ∞ñ┐ fprintf(3S) ╖┴╝░ñ╟╝░ñ≥Ñ╒Ñ⌐í╝Ñ▐Ñ├Ñ╚ñ╖íóÑ╒Ñ⌐í╝Ñ▐Ñ├Ñ╚╕σñ╬╩╕╗·╬≤ñ≥╩╓ñ╖ñ▐ñ╣íú

sub(for, repl, in)
╩╕╗·╬≤ in ╞Γñ╬└╡╡¼╔╜╕╜ for ñ╬║╟╜Θñ╬ÑñÑ≤Ñ╣Ñ┐Ñ≤Ñ╣ñ╚╩╕╗·╬≤ repl ñ≥├╓ñ¡┤╣ñ¿íó├╓ñ¡┤╣ñ¿ñ┐▓≤┐⌠ñ≥╩╓ñ╖ñ▐ñ╣íúin ñ≥╗╪─Ωñ╖ñ╩ññ╛∞╣τíóawk ñ╧╕╜║▀ñ╬Ñ∞Ñ│í╝Ñ╔($0)ñ╟├╓ñ¡┤╣ñ¿ñ≥╣╘ñ╩ñññ▐ñ╣íú

substr(s, m, n)
░╠├╓ m ñ╟╗╧ñ▐ñδ s ñ╬ n ╩╕╗·╩¼ñ╬Ñ╡Ñ╓╩╕╗·╬≤ñ≥╩╓ñ╖ñ▐ñ╣íú

╞■╜╨╬╧┴╚ñ▀╣■ñ▀┤╪┐⌠ñ╦ñ╧íó░╩▓╝ñ╬ñΓñ╬ñ¼ñóñΩñ▐ñ╣íú

close(filename)
filename ñ╟╗╪─Ωñ╖ñ┐Ñ╒ÑíÑñÑδñ▐ñ┐ñ╧Ñ╤ÑñÑ╫ñ≥Ñ»Ñφí╝Ñ║ñ╖ñ╞íóÑ╣Ñ╞í╝Ñ┐Ñ╣ñ≥╩╓ñ╖ñ▐ñ╣íú

cmd | getline
cmd ñ╬╜╨╬╧ñ≥ getline ñ╦Ñ╤ÑñÑ╫ñ╖ñ▐ñ╣íúgetline ñ╦╕σ┬│ñ╣ñδ│╞╕╞ñ╙╜╨ñ╖ñ╧íócmd ñ½ñΘñ╬╜╨╬╧ñ╬╝íñ╬╣╘ñ≥╩╓ñ╖ñ▐ñ╣íú

getline
$0 ñ≥╕╜║▀ñ╬╞■╬╧Ñ╒ÑíÑñÑδñ½ñΘñ╬╝íñ╬╞■╬╧Ñ∞Ñ│í╝Ñ╔ñ╦└▀─Ωñ╖ñ▐ñ╣íú

getline <file
$0 ñ≥ file ñ½ñΘñ╬╝íñ╬Ñ∞Ñ│í╝Ñ╔ñ╦└▀─Ωñ╖ñ▐ñ╣íú

getline x
┬σñ∩ñΩñ╦╩╤┐⌠ x ñ≥└▀─Ωñ╖ñ▐ñ╣íú

getline x <file
file ñ╬╝íñ╬Ñ∞Ñ│í╝Ñ╔ñ½ñΘ x ñ≥└▀─Ωñ╖ñ▐ñ╣íú

system(cmd)
cmd ñ≥╝┬╣╘ñ╖íóñ╜ñ╬╜¬╬╗Ñ│í╝Ñ╔ñ≥╩╓ñ╖ñ▐ñ╣íú

┴┤ñ╞ñ╬╖┴╝░ñ╬ getline ñ╧íó└╡╛∩╞■╬╧ñ╦ñ╧ 1íóÑ╒ÑíÑñÑδ╜¬├╝ñ╟ñ╧ 0íóÑ¿ÑΘí╝ñ╬╛∞╣τñ╧ -1 ñ≥╩╓ñ╖ñ▐ñ╣íú

awk ñ╧ñ▐ñ┐ѵí╝Ñ╢ñ¼─Ω╡┴▓─╟╜ñ╩┤╪┐⌠ñΓ─≤╢íñ╖ñ▐ñ╣íú┤╪┐⌠ñ╧╝íñ╬ñΦñªñ╦(Ñ╤Ñ┐í╝Ñ≤-ÑóÑ»Ñ╖ÑτÑ≤Ñ╣Ñ╞í╝Ñ╚ÑßÑ≤Ñ╚ñ╬Ñ╤Ñ┐í╝Ñ≤╔⌠ñ╟)─Ω╡┴ñ╡ñ∞ñ▐ñ╣íú

 
   function name(args,...) { stmts } 
ñ▐ñ┐ñ╧
 
   func name(args,...) { stmts } 
┤╪┐⌠ñ╬░·ñ¡┐⌠ñ╧íóÑ╣ѽÑΘí╝ñ╟ñóñ∞ñ╨├═ñ╟íó╗▓╛╚ñ╟ñóñ∞ñ╨╟█╬≤╠╛ñ╟┼╧ñ╡ñ∞ñ▐ñ╣íú░·ñ¡┐⌠╠╛ñ╧┤╪┐⌠ñ╦┬╨ñ╖ñ╞Ñφí╝ѽÑδñ╟ñ╣íú┬╛ñ╬┴┤ñ╞ñ╬╩╤┐⌠╠╛ñ╧Ñ░Ñφí╝Ñ╨Ñδñ╟ñ╣íú┤╪┐⌠ñ╧Ñ═Ñ╣Ñ╚ñ╖ñ╞╕╞ñ╙╜╨ñ╗íó║╞╡ó▓─╟╜ñ╟ñ╣íú├═ñ≥╩╓ñ╣ñ╦ñ╧ return Ñ╣Ñ╞í╝Ñ╚ÑßÑ≤Ñ╚ñ≥╗╚═╤ñ╖ñ▐ñ╣íú

╗╚═╤╬π

72 ╩╕╗·ñΦñΩ─╣ññ╣╘ñ≥Ñ╫ÑΩÑ≤Ñ╚ñ╖ñ▐ñ╣íú
 
   length > 72 

║╟╜Θñ╬ 2 ñ─ñ╬Ñ╒Ñúí╝ÑδÑ╔ñ≥╡╒╜τñ╦Ñ╫ÑΩÑ≤Ñ╚ñ╖ñ▐ñ╣íú

 
   { print $2, $1 } 

Ñ│Ñ≤Ñ▐ñ╚Ñ╓ÑΘÑ≤Ñ»ñ╬ñ╔ñ┴ñΘñ½ñ▐ñ┐ñ╧╬╛╩²ñ╚íóÑ┐Ñ╓ñ╟╩¼ñ▒ñΘñ∞ñδ╞■╬╧Ñ╒Ñúí╝ÑδÑ╔ñ╚╞▒ñ╕íú

 
   BEGIN	{ FS = ",[ \t]*|[ \t]+" } 
   	{ print $2, $1 } 

║╟╜Θñ╬ѽÑΘÑαñ≥▓├╗╗ñ╖íó╣τ╖╫ñ╚╩┐╢╤ñ≥Ñ╫ÑΩÑ≤Ñ╚ñ╖ñ▐ñ╣íú

 
   	{ s += $1 } 
   END	{ print "sum is", s, " average is", s/NR } 

Ñ╒Ñúí╝ÑδÑ╔ñ≥╡╒╜τñ╦Ñ╫ÑΩÑ≤Ñ╚ñ╖ñ▐ñ╣íú

 
   { for (i = NF; i > 0; --i) print $i } 

start ñ╚ stop ñ╬┤╓ñ╬ñ╣ñ┘ñ╞ñ╬╣╘ñ≥Ñ╫ÑΩÑ≤Ñ╚ñ╖ñ▐ñ╣íú

 
   /start/, /stop/ 

║╟╜Θñ╬Ñ╒Ñúí╝ÑδÑ╔ñ¼┴░ñ╬╣╘ñ╬ñΓñ╬ñ╚░█ñ╩ñδñ╣ñ┘ñ╞ñ╬╣╘ñ≥Ñ╫ÑΩÑ≤Ñ╚ñ╖ñ▐ñ╣íú

 
   $1 != prev { print; prev = $1 } 

echo(1) ñ╬Ñ╖Ñ▀ÑσÑ∞í╝Ñ╚

 
   BEGIN	{ 
   	for (i = 1; i < ARGC; i++) 
   		printf "%s", ARGV[i] 
   	printf "\n" 
   	exit 
   	} 

5 ░╩╣▀ñ╬Ñ┌í╝Ñ╕╚╓╣µñ≥╡¡╞■ñ╖ñ╞Ñ╒ÑíÑñÑδñ≥Ñ╫ÑΩÑ≤Ñ╚ñ╖ñ▐ñ╣íú

 
   /Page/	{ $2 = n++; } 
   	{ print } 

Ñ╫ÑφÑ░ÑΘÑαñ¼ prog ñ╚╕└ñª╠╛┴░ñ╬Ñ╒ÑíÑñÑδñ╦ñóñδñ╚ñ╣ñδñ╚íó╝íñ╬Ñ│Ñ▐Ñ≤Ñ╔ÑΘÑñÑ≤ñ╧Ñ╒ÑíÑñÑδ input ñ≥ 5 ñ½ñΘ╗╧ñ▐ñδÑ┌í╝Ñ╕╚╓╣µñ≥ñ─ñ▒ñ╞Ñ╫ÑΩÑ≤Ñ╚ñ╖ñ▐ñ╣íú

awk -f prog n=5 input.

Ñ╒ÑíÑñÑδ

/usr/lib/locale/locale/LC_MESSAGES/uxawk
╕└╕∞╞├═¡ñ╬ÑßÑ├Ñ╗í╝Ñ╕Ñ╒ÑíÑñÑδ(environ(5) ñ╬ LANG ╗▓╛╚)

┤╪╧ó╣α╠▄

fprintf(3S), grep(1), lex(1), sed(1)

A. V. Aho, B. W. Kernighan, P. J. Weinberger, The awk Programming Language Addison-Wesley, 1988

├φ░╒

nawk ñ╧íóawk ñ╚╞▒ñ╕ñΓñ╬ñ╟ñ╣íúnawk is equivalent to awk.

╞■╬╧ñ╬╢⌡╟≥Ñ╣Ñ┌í╝Ñ╣ñ╧íóÑ╒Ñúí╝ÑδÑ╔ñ¼┤╪╖╕ñ╣ñδ╛∞╣τñ╦ñ╧╜╨╬╧ñ╡ñ∞ñ▐ñ╗ñ≤íú

┐⌠├═ñ╚╩╕╗·╬≤ñ╬┤╓ñ╟ñ╧íó╠└╝¿┼¬ñ╩╖┐╩╤┤╣ñ╧ñóñΩñ▐ñ╗ñ≤íú╝░ñ≥┐⌠├═ñ╚ñ╖ñ╞░╖ñªñ┐ñßñ╦ñ╧íó╝░ñ╦ 0 ñ≥▓├╗╗ñ╖ñ▐ñ╣íú╝░ñ≥╩╕╗·╬≤ñ╚ñ╖ñ╞░╖ñªñ┐ñßñ╦ñ╧íóÑ╠Ñδ╩╕╗·╬≤("")ñ≥╧ó╖δñ╖ñ▐ñ╣íú


SCO UnixWare Forum Beta Release (BL12) -- September 1997
© 1997 The Santa Cruz Operation, Inc. All rights reserved.