AWK(1)	UNIX¥³¥Þ¥ó¥É	AWK(1)

 [Ì¾Á°]
awk - ¥Ñ¥¿¡¼¥óÁöºº¡¢½èÍý¸À¸ì

 [·Á¼°]
awk [-Fc] [¥¹¥¯¥ê¥×¥È] [¥Ç¡¼¥¿¥Õ¥¡¥¤¥ë]...

 [µ¡Ç½ÀâÌÀ]
awk¤Ï¥¹¥¯¥ê¥×¥ÈÆâ¤ÇÄêµÁ¤·¤¿¥Ñ¥¿¡¼¥ó¤È°ìÃ×¤¹¤ë¥é¥¤¥ó¤¬¤¢¤ë¤«¥Ç¡¼¥¿¥Õ¥¡¥¤¥ë¤ò¥¹¥­¥ã¥ó¤·¤Þ¤¹¡£¤Þ¤¿¥Ç¡¼¥¿¥Õ¥¡¥¤¥ëÆâ¤Ë°ìÃ×¤¹¤ë¥Ñ¥¿¡¼¥ó¤ò¸«¤Ä¤±¤¿»þ¼Â¹Ô¤µ¤ì¤ë¥¢¥¯¥·¥ç¥ó¤ò¥¹¥¯¥ê¥×¥ÈÆâ¤ËÄêµÁ¤Ç¤­¤Þ¤¹¡£
¥Ñ¥¿¡¼¥ó¤Ï¥¹¥¯¥ê¥×¥È¤Ëµ­½Ò¤·¤Þ¤¹¤¬¡¢¥¹¥¯¥ê¥×¥È¥Õ¥¡¥¤¥ë¤Ëµ­½Ò¤·-f¥Õ¥¡¥¤¥ëÌ¾¤Ç»ØÄê¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£

¥Õ¥¡¥¤¥ëÌ¾¤Î»ØÄê¤¬¤Ê¤¤»þ¤ÏÉ¸½àÆþÎÏ¤«¤éÆÉ¤ß¹þ¤à¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¥Õ¥¡¥¤¥ëÌ¾'-'¤ÏÉ¸½àÆþÎÏ¤òÉ½¤·¤Þ¤¹¡£¥Ñ¥¿¡¼¥ó¤È°ìÃ×¤¹¤ë¥é¥¤¥ó¤òÆÉ¤ß¹þ¤à¤È¥Ñ¥¿¡¼¥ó-¥¢¥¯¥·¥ç¥ó¥¹¥Æ¡¼¥È¥á¥ó¥È¤Î¥¢¥¯¥·¥ç¥óÉô¼Â¹Ô¤·¤Þ¤¹¡£

ÆþÎÏ¤·¤¿³Æ¥é¥¤¥ó¤Ï¥¹¥Ú¡¼¥¹¤Ë¤è¤ê¥Õ¥£¡¼¥ë¥É¤ËÊ¬³ä¤µ¤ì¤Þ¤¹¡£(FSÊÑ¿ô¤ËÀßÄê¤¹¤ë¤³¤È¤Ë¤è¤êÇ¤°Õ¤Î¥Õ¥£¡¼¥ë¥É¥»¥Ñ¥ì¡¼¥¿¤ò»ØÄê¤Ç¤­¤Þ¤¹¡£) ³Æ¥Õ¥£¡¼¥ë¥É¤Ï$1¡¢$2...¤Ë³ÊÇ¼¤µ¤ì¤Þ¤¹¡£$0¤Ë¤Ï¥é¥¤¥óÁ´ÂÎ¤¬³ÊÇ¼¤µ¤ì¤Þ¤¹¡£

¥Ñ¥¿¡¼¥ó¥¢¥¯¥·¥ç¥ó¥¹¥Æ¡¼¥È¥á¥ó¥È¤Ï¼¡¤Î·Á¼°¤Ç¤¹¡£

	pattern {action}

{action}¤¬Ì¤»ØÄê¤Î¤È¤­¤Ï°ìÃ×¤·¤¿¥é¥¤¥ó¤Î°õ»ú¤òÉ½¤·¤Þ¤¹¡£¤Þ¤¿pattern¤¬Ì¤»ØÄê¤Î¾ì¹ç¤Ï¾ï¤Ë°ìÃ×¤¹¤ë¤³¤È¤òÉ½¤·¤Þ¤¹¡£

¥¢¥¯¥·¥ç¥ó¥¹¥Æ¡¼¥È¥á¥ó¥È¤ÎÎã¤ò°Ê²¼¤Ë¼¨¤·¤Þ¤¹¡£

	if(¾ò·ï)¥¹¥Æ¡¼¥È¥á¥ó¥È[else ¥¹¥Æ¡¼¥È¥á¥ó¥È]
	while(¾ò·ï) ¥¹¥Æ¡¼¥È¥á¥ó¥È
	for(¼°;¾ò·ï;¼°)¥¹¥Æ¡¼¥È¥á¥ó¥È
	break
	continue
	{[¥¹¥Æ¡¼¥È¥á¥ó¥È]...}
	ÊÑ¿ô = ¼°
	print[¼°¥ê¥¹¥È][>¼°]
	printf format [,¼°¥ê¥¹¥È][>¼°]
	next #¥é¥¤¥ó¾å¤Î»Ä¤ê¤Î¥Ñ¥¿¡¼¥ó¤ò¥¹¥­¥Ã¥×
	exit #»Ä¤ê¤ÎÆþÎÏ¤ò¥¹¥­¥Ã¥×

¥¹¥Æ¡¼¥È¥á¥ó¥È¤Ï¥»¥ß¥³¥í¥ó¡¢¥Ë¥å¡¼¥é¥¤¥ó¡¢'}'¤Ç½ªÎ»¤·¤Þ¤¹¡£¶õ¤Î¼°¥ê¥¹¥È¤Ï¥é¥¤¥ó¤½¤Î¤â¤Î¤ò°ÕÌ£¤·¤Þ¤¹¡£¼°¤ÏÅ¬Åö¤ÊÊ¸»úÎó¡¢¿ôÃÍ¤ò¤È¤ê¡¢+¡¢-¡¢*¡¢/¡¢%¤Ê¤É¤Î±é»»»Ò¤ò»ÈÍÑ¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£ ¤µ¤é¤ËC¸À¸ì¤ÈÆ±ÍÍ¤Ë++¡¢--¡¢+=¡¢-=¡¢*=¡¢/=¡¢%=¤Ê¤É¤â»ÈÍÑ¤Ç¤­¤Þ¤¹¡£ÊÑ¿ô¤Ï¥¹¥«¥é¡¢ÇÛÎóÍ×ÁÇ¡¢¥Õ¥£¡¼¥ë¥É¤ò¼è¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¤Þ¤¿³ÆÊÑ¿ô¤Ïnull¤Ç½é´ü²½¤µ¤ì¤Þ¤¹¡£ÇÛÎóÍ×ÁÇÌ¾¤Ï¿ôÃÍ¤À¤±¤Ç¤Ê¤¯Ê¸»úÎó¤ÇÉ½µ­¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£Ê¸»úÄê¿ô¤ÎÄêµÁ¤Ï"..."¤Î¤è¤¦¤Ë¤ª¤³¤Ê¤¤¤Þ¤¹¡£

print¥¹¥Æ¡¼¥È¥á¥ó¥È¤Ï¡¢¤½¤Î°ú¿ô¤òÉ¸½à½ÐÎÏ¤Ë¥Õ¥£¡¼¥ë¥É¥»¥Ñ¥ì¡¼¥¿¤ÎÃÍ¤ÇÊ¬³ä¤·¡¢¥ì¥³¡¼¥É¥»¥Ñ¥ì¡¼¥¿¤ò½ªÃ¼¤È¤·¤¿·Á¼°¤Ç°õ»ú¤·¤Þ¤¹¡£printf¥¹¥Æ¡¼¥È¥á¥ó¥È¤Î½ñ¼°¤Ë´Ø¤·¤Æ¤Ïprintf(3S)¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£

ÁÈ¤ß¹þ¤ß´Ø¿ô¤Îlength¤Ï¡¢Ê¸»úÎó¤ò°ú¿ô¤È¤·¤¿¤È¤­¤Ï¤½¤ÎÄ¹¤µ¤ò¡¢¤Þ¤¿°ú¿ô¤ò»ØÄê¤·¤Ê¤±¤ì¤Ð¡¢¤½¤Î¥é¥¤¥óÁ´ÂÎ¤ÎÄ¹¤µ¤òÊÖ¤·¤Þ¤¹¡£¤½¤ÎÂ¾ÁÈ¤ß¹þ¤ß´Ø¿ô¤È¤·¤Æexp¡¢log¡¢sqrt¡¢int¤Ê¤É¤¬¤¢¤ê¤Þ¤¹¡£
substr(s, m, n)¤ÏÊ¸»úÎós¤ÎmÊ¸»úÌÜ¤«¤énÊ¸»ú¤ÎÉôÊ¬Ê¸»úÎó¤òÊÖ¤·¤Þ¤¹¡£sprintf(fmt, expr, expr, ...)¤Ïfmt¤Ë¤è¤ê¥Õ¥©¡¼¥Þ¥Ã¥È¤µ¤ì¤¿Ê¸»úÎó¤òÊÖ¤·¤Þ¤¹¡£       

¥Ñ¥¿¡¼¥ó¤Ï(!¡¢||¡¢&&¤Ê¤É¤Ë¤è¤ë)Àµµ¬É½¸½¤ä´Ø·¸¼°¤ÎÁÈ¤ß¹ç¤ï¤»¤Ë¤è¤ê¹½À®¤µ¤ì¤Þ¤¹¡£Àµµ¬É½¸½¤ÏegrepÆ±ÍÍ¥¹¥é¥Ã¥·¥å¤Ç°Ï¤ó¤Çµ­½Ò¤·¤Þ¤¹¡£Àµµ¬É½¸½Ã±ÂÎ¤Çµ­½Ò¤µ¤ì¤¿¾ì¹ç¤Ï(¥Õ¥£¡¼¥ë¥É¤Î»ØÄê¤¬¤Ê¤¤»þ)¤ÏÆþÎÏ¥é¥¤¥óÁ´ÂÎ¤ËÅ¬ÍÑ¤µ¤ì¤Þ¤¹¡£¤½¤ÎÂ¾¤Ë¡¢Àµµ¬É½¸½¤Ï´Ø·¸¼°¤ÎÃæ¤Ëµ­½Ò¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

¥Ñ¥¿¡¼¥ó¤Ï¥³¥ó¥Þ¤Ç¶èÀÚ¤Ã¤¿¡¢Æó¤Ä¤Î¥Ñ¥¿¡¼¥ó¤Çµ­½Ò¤µ¤ì¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£¤³¤Î¾ì¹ç¼Â¹Ô¤µ¤ì¤ëÈÏ°Ï¤Ï¡¢½é¤á¤Î¥¢¥¯¥·¥ç¥ó¤¬°ìÃ×¤·¤¿¥é¥¤¥ó¤«¤éÆóÈÖÌÜ¤Î¥¢¥¯¥·¥ç¥ó¤¬°ìÃ×¤·¤¿¥é¥¤¥ó¤Þ¤Ç¤Ç¤¹¡£	

´Ø·¸¼°¤Î·Á¼°¤Ï¼¡¤Î¤¤¤º¤ì¤«¤Ç¤¹¡£

	¼° matchop Àµµ¬É½¸½
	¼° relop ¼°

relop¤È¤ÏC¸À¸ì¤Î6¤Ä¤Î´Ø·¸±é»»»Ò¤ÎÃæ¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ê¡¢matchop¤Ï~(´Þ¤à)¤Þ¤¿¤Ï!~(´Þ¤Þ¤º)¤Î¤¤¤º¤ì¤«¤Ç¤¹¡£¾ò·ï¼°¤Ï¿ô¼°¡¢´Ø·¸¼°¡¢¤Þ¤¿¤Ï¤½¤ì¤é¤ÎÏÀÍý·ë¹ç¤Î¤¤¤º¤ì¤«¤Ç¤¹¡£

ÆÃ¼ì¤Ê¥Ñ¥¿¡¼¥ó¤È¤·¤Æ¡¢BEGIN ¤È END¤¬¤¢¤ê¤Þ¤¹¡£BEGIN¤Ï¥Õ¥¡¥¤¥ë¤òÆÉ¤ß¹þ¤à°ÊÁ°¤òÉ½¤·¡¢ºÇ½é¤Ë½ñ¤«¤ì¤ë¥Ñ¥¿¡¼¥ó¤Ç¤¹¡£END¤Ï¥Õ¥¡¥¤¥ë¤òÆÉ¤ß¹þ¤ó¤À¸å¤òÉ½¤·¡¢ºÇ¸å¤Ë½ñ¤«¤ì¤ë¥Ñ¥¿¡¼¥ó¤Ç¤¹¡£

Ê¸»úÎóc¤ò¥Õ¥£¡¼¥ë¥É¥»¥Ñ¥ì¡¼¥¿¤Ë»ØÄê¤¹¤ë»þ¤Ï¼¡¤Î¤è¤¦¤Ëµ­½Ò¤·¤Þ¤¹¡£

	BEGIN {FC="c"}

¤Þ¤¿¤Ï¡¢¼Â¹Ô»þ¤Ë-Fc¥ª¥×¥·¥ç¥ó¤ò»ØÄê¤·¤Æ¤âÆ±ÍÍ¤Ç¤¹¡£

ÆÃ¼ì¤ÊÊÑ¿ô¤È¤·¤Æ¡¢¼¡¤Î¤â¤Î¤¬¤¢¤ê¤Þ¤¹¡£

	NF:¥«¥ì¥ó¥È¥ì¥³¡¼¥É¤Î¥Õ¥£¡¼¥ë¥É¤Î¿ô
	NR:ÆÉ¤ß¹þ¤ó¤À¥ì¥³¡¼¥É¤Î¿ô
	FILENAME:ÆþÎÏ¥Õ¥¡¥¤¥ë¤ÎÌ¾Á°
	OFS:½ÐÎÏÍÑ¤Î¥Õ¥£¡¼¥ë¥É¥»¥Ñ¥ì¡¼¥¿(¥Ç¥Õ¥©¥ë¥È¤Ï¥Ö¥é¥ó¥¯)
	ORS:½ÐÎÏÍÑ¤Î¥ì¥³¡¼¥É¥»¥Ñ¥ì¡¼¥¿(¥Ç¥Õ¥©¥ë¥È¤Ïnewline)
	OFMT:¿ô»ú¹àÌÜ¤Î½ÐÎÏ¥Õ¥©¡¼¥Þ¥Ã¥È(¥Ç¥Õ¥©¥ë¥È¤Ï"%.6g")

 [ÆüËÜ¸ìµ¡Ç½]
¥¹¥¯¥ê¥×¥ÈÆâ¤ÇÊÑ¿ôÌ¾¡¢ÇÛÎóÌ¾¡¢ÇÛÎóÍ×ÁÇÌ¾¤òÆüËÜ¸ì¤Çµ­½Ò¤Ç¤­¤Þ¤¹¡£ÆüËÜ¸ì¥Ç¡¼¥¿¤Î¥Ñ¥¿¡¼¥óÁöºº¤¬²ÄÇ½¤Ç¤¹¡£Ã¢¤·¡¢¥Õ¥£¡¼¥ë¥É¥»¥Ñ¥ì¡¼¥¿¡¢¥ì¥³¡¼¥É¥»¥Ñ¥ì¡¼¥¿¤Ë¡¢ÆüËÜ¸ì¤ò»ØÄê¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£
	
 [»ÈÍÑÎã]
72Ê¸»ú°Ê¾å¤Î¥é¥¤¥ó¤ò½ÐÎÏ¤¹¤ë¡£
	length > 72

Âè1¥Õ¥£¡¼¥ë¥É¤ÈÂè2¥Õ¥£¡¼¥ë¥É¤ò½ÐÎÏ¤¹¤ë¡£
	{print $1,$2}

Âè1¥Õ¥£¡¼¥ë¥É¤ÎÃÍ¤òÂ­¤·¹þ¤ó¤Ç¹Ô¤­¡¢ºÇ¸å¤ËÁí·×¤ÈÊ¿¶Ñ¤ò½ÐÎÏ¤¹¤ë¡£
	{·×+=$1}
	END{ print "Áí·×",·×,"Ê¿¶Ñ",·×/NR}

ºÇ½ª¥Õ¥£¡¼¥ë¥É¤«¤é¡¢Âè1¥Õ¥£¡¼¥ë¥É¤Þ¤Ç½ç¤Ë½ÐÎÏ¤¹¤ë¡£
	{for(i=NF;i>0;--i)print$1}

Ê¸»úÎóstart,stop¤Î¤¢¤ë¥é¥¤¥ó¤È¤½¤Î´Ö¤Î¥é¥¤¥ó¤¹¤Ù¤Æ¤ò½ÐÎÏ¤¹¤ë¡£
	/start/,/stop/

Âè1¥Õ¥£¡¼¥ë¥É¤¬°ÊÁ°¤Î¤½¤ì¤È°Û¤Ê¤ë¥é¥¤¥ó¤ò½ÐÎÏ¤¹¤ë¡£
	$1 != Á°{print;Á°=$1}

 [´ØÏ¢»ö¹à]
lex(1), sed(1)
A. V. ¥¨¥¤¥Û¡¢B. W. ¥«¡¼¥Ë¥Ï¥ó¡¢P. J. ¥ï¥¤¥ó¥Ð¡¼¥¬¡¼¡¢ ¥×¥í¥°¥é¥ß¥ó¥°¸À¸ìAWK

 [Ãí°Õ»ö¹à]
¿ôÃÍ¤ÈÊ¸»úÎó¤ÎÌÀÇò¤ÊÊÑ´¹¤Ï¤¢¤ê¤Þ¤»¤ó¡£¿ôÃÍ¤È¤·¤Æ°·¤¦¾ì¹ç¤Ï+0¤È¤¹¤ë¤³¤È¤Ë¤è¤ê¿ôÃÍ¤ËÊÑ´¹¤µ¤ì¤Þ¤¹¡£¤Þ¤¿Ê¸»ú¤È¤·¤Æ°·¤¦¾ì¹ç¤Ë¤Ï""¤òÉÕ²Ã¤¹¤ë¤³¤È¤Ë¤è¤êÊ¸»úÎó¤È¸«¤Ê¤¹¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£