ææ°çã®GNU AWKãå ¥æ
ãGNU AWKã®ã³ã¼ãã¯ç¾å¨GNU Savannahã®gitãªãã¸ããªã«ããã¾ãããããã£ã¦ãgitã³ãã³ããç¨ãã¦ææ°çãå ¥æãããã¨ãã§ãã¾ãã
$ git clone 'git://git.savannah.gnu.org/gawk.git'
ãä¸è¨ã³ãã³ããå®è¡ããã¨ã«ã¬ã³ããã£ã¬ã¯ããªã«gawkã¨ããååã®ãã£ã¬ã¯ããªãä½æããããã®ä¸ã«GNU AWKã®masterã³ã¼ãããã¦ã³ãã¼ãããã¾ãã
ãããããã«ãããã«ã¯ä»¥ä¸ã®ããã«ãã¾ãã
$ cd gawk $ ./configure && make
ã&&ã¯åã®ã³ãã³ãã®æ»ãå¤ã0ãã¤ã¾ãã³ãã³ããæåããã°æ¬¡ã®ã³ãã³ããå®è¡ããã¨ããæå³ã§ãã
ãã¤ã³ã¹ãã¼ã«ããã«ã¯rootã«ãªãã以ä¸ã®ã³ãã³ããå®è¡ãã¾ãã
# make install
ãã¤ã³ã¹ãã¼ã«å ã¯configureã¹ã¯ãªããå®è¡æãmakeã³ãã³ãå®è¡æã«æå®ã§ãã¾ãããããã©ã«ãã§ã¯/usr/local/binã«ãªãã¾ããããã§ææ°ã®GNU AWK ãã¤ã³ã¹ãã¼ã«ããã¾ããããããææ°ã®GNU AWKã«ã¤ãã¦ã®è§£èª¬ããã¦ããã¾ããããã£ã¹ããªãã¥ã¼ã·ã§ã³ãã¨ã«ç¨æããã¦ããGNU AWKã¨ç°ãªãå ´åãããã¾ãã®ã§ãã注æãã ããã
æ£è¦è¡¨ç¾ã®æ¡å¼µ
ãæåã«ç´¹ä»ããã®ã¯æ£è¦è¡¨ç¾ã®æ¡å¼µã§ããã¢ã«ãã¡ãããã¾ãã¯æ°åã®é£ç¶ãã5åã®æååã«ãããããããã¨ããã¨ãå¾æ¥ã¯å¤§å¤ã§ããã
[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]
ããã¡ãããããã¯ããã§åãããããã®ã§ããããã£ã¨æ°ãå¤ããªã£ã¦ããã¨èªã¿ã¥ãããã®ã«ãªã£ã¦ãã¦ãã¾ãã¾ãããã£ã¨ãæ£è¦è¡¨ç¾ã¯æ±ºãã¦èªã¿ããããã®ã§ã¯ããã¾ããããGNU AWKã§ã¯åæ°ãæå®ãããã¨ãã§ãã¾ãã
[a-zA-Z0-9]{5}
ãã¹ãããªãã¾ããããå°ãå¤ãGNU AWK ã§ãèµ·åæã®ãªãã·ã§ã³ï¼--re-intervalï¼ã§ãã®ãããªè¡¨ç¾ã使ããã¨ã¯å¯è½ã§ããããææ°ã®GNU AWKã§ã¯ããã©ã«ãã§ä½¿ããã¨ãå¯è½ã«ãªãã¾ãããéååãããªãã·ã§ã³ã§æå®ã§ããã®ã§ãããæ¨æºå®è£ ãããã¾ã§ã«æéãããã£ãã®ã¯ã¡ã³ããã¼ã®æ éãã®è¡¨ãã ã¨æãã¾ãã
ãã¾ãããã®[a-zA-Z0-9]ã®ãããªéåã表ãæ£è¦è¡¨ç¾ãæ¡å¼µããã¦ãã¾ãããã®ããã«ã¢ã«ãã¡ãããã¨æ°åã表ãæ£è¦è¡¨ç¾ã®éåã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
[[:alnum:]]
ãè§æ¬å¼§ãäºéã«ãªã£ã¦ããç¹ã«æ³¨æãã¦ãã ãããman ãã¼ã¸ã®æ£è¦è¡¨ç¾ã§ã¯[:alnum:]ã¨ãªã£ã¦ãã¾ãããmanãã¼ã¸ã«è¨è¿°ããã¦ããé¨åã¯ä¸èº«ã®a-zA-Z0-9ã ãã§ãããå®éã«æ£è¦è¡¨ç¾ã¨ãã¦ç¨ããå ´åã«ã¯ãä¸è¨ã®ããã«è§æ¬å¼§ãäºéã«è¨è¿°ãã¾ããã¡ã¼ãªã³ã°ãªã¹ãã«æãããã質åã§ãæã è¦ããã¾ãã
ãGNU AWKã§ã¯ããã«èª¤è§£ãæããããªæ£è¦è¡¨ç¾ã«å°ãæãå ¥ãã¦ãã¾ãã
$ echo "abc" | LC_ALL=en_US gawk '/[A-Z]/' abc
ãabcã大æåã¨ããã®ã¯å¤ã§ããããããã¯ä½¿ç¨ç°å¢ã®è¨èªè¨å®ã«ãã£ã¦ã¯[A-Z]ã大æåã ãã®éåã表ç¾ããªãããã«èµ·ãããããã®ã§ãgrepãsedã³ãã³ãã§ãåæ§ã®åé¡ãããã¾ããããã«å¯¾ãã¦GNU AWKã§ã¯[a-z]ã¯å°æåã ãã®éåã[A-Z]ã¯å¤§æåã ãã®éåã示ãããã«å·¥å¤«ãã¦ããã¾ããGNU AWKã®ã¡ã³ããã¼ã§ããArnold Robbinsããããã§é¢åãªè³ªåã«çããå¿ è¦ããªããªã£ããã¨ãããããªãã¥ã¢ã³ã¹ã§ç´¹ä»ãã¦ãã¾ãããGNUå ¨ä½ã®ä¸ã§ãgrepã³ãã³ããsedã³ãã³ããã©ããã¦ãããã話é¡ã¨ãªã£ã¦ãããä»å¾ã®AWKã®ååã注ç®ããã¦ãã¾ãã
ããã®å ´åã«ã¯ãå ã»ã©ç´¹ä»ããæ£è¦è¡¨ç¾éå[:upper:]ã§åé¿ãããã¨ãã§ãã¾ã
$ echo "abc" | LC_ALL=en_US gawk '/[[:upper:]]/' ï¼ä½ãåºåãããªãï¼
ãGNU AWKã§æ¡å¼µãããæ£è¦è¡¨ç¾ã¯å¤ããããã¨ã¦ããã®ç´é¢ã§ç´¹ä»ãããããã®ã§ã¯ããã¾ãããmanãã¼ã¸ãinfoã³ãã³ãã§èª¿ã¹ã¦ã¿ã¦ãã ããã
RSã®æ£è¦è¡¨ç¾å¯¾å¿ãRTã®è¿½å
ãçµè¾¼å¤æ°RSã¯é常ã®AWKã§ã¯æååããæå®ãããã¨ãã§ãã¾ããã§ããããã®ãããæ£è¦è¡¨ç¾ã§ã¬ã³ã¼ããåå²ãããã¦ãã§ãã¾ããã§ããããGNUæ¡å¼µã«ããçµè¾¼å¤æ°RSã«æ£è¦è¡¨ç¾ãç¨ãããã¨ãå¯è½ã«ãªã£ã¦ãã¾ãã
ãå®éã«çµè¾¼å¤æ°RSã«æ£è¦è¡¨ç¾ãç¨ããã¨ä¾¿å©ãªå ´åã¯ã©ã®ãããªãã®ãããã§ããããï¼ ããã¯æ§é åãããããã¹ããã¡ã¤ã«ãä¾ãã°HTMLãXMLã®ãããªãã®ã§ããããããããã¹ããã¡ã¤ã«ã¯æ¹è¡ã§ã¯ãªãã¿ã°ã«ããåºåããã¾ãã
ãä¾ãã°ãWebãã¼ã¸ã®ã¿ã¤ãã«ãæ½åºããä¸è¡ééã¯ã以ä¸ã®ããã«ç°¡åã«è¨è¿°ãããã¨ãã§ããããã«ãªãã¾ãã
$ curl -s 'http://gauc.no-ip.org/awk-users-jp/' | \ gawk -v RS='</?title[ ]?[^>]*>\r?\n?' 'NR==2' AWK Users JP :: æ¥æ¬ã® AWK ã¦ã¼ã¶ã®ããã®ãããµã¤ã
ããã¦ãæ£è¦è¡¨ç¾ã§åå²ããã¨ãå®éã«ç¨ããããåºåãã¯ä½ã ã£ãããç¥ããããªãã¾ããGNU AWKã§ã¯ããã®è§£ã¨ãã¦çµè¾¼å¤æ°RTãããã¾ããçµè¾¼å¤æ°RTã«ã¯çµè¾¼å¤æ°RSã§åºåãããéã®åºåãããã¬ã³ã¼ãã»ãã¬ã¼ã¿ã¼ã®æåãã®ãã®ãæ ¼ç´ããã¾ãã
$ curl -s 'http://gauc.no-ip.org/awk-users-jp/' | \ gawk -v RS='</?title[ ]?[^>]*>\r?\n?' '{print RT}' <title> </title>
ãã¤ã¾ããå ã»ã©ã®Web ãã¼ã¸ã®ã¿ã¤ãã«ãæãåºããã®ã§ä½¿ãããçµè¾¼å¤æ°RSã¯<title>ã¨</title>ã§ãã£ããã¨ãåããã¾ãã
ãã¾ããããã§ã¯è©³ç´°ãç´¹ä»ãã¾ãããããã¡ã¤ã«å ¨ä½ã1ã¤ã®ã¬ã³ã¼ãã¨ãã¦æ±ããããçµè¾¼å¤æ°RSã«\0ã使ããã¨ãã§ãã¾ãããããæ§é åãããããã¹ããæ±ãå¸ç³ã®ä¸ã¤ã§ããããã¾ããçµè¾¼å¤æ°RSãRTã使ãã°Webãã¼ã¸ã®CGIã§POSTãããå 容ãæ±ããããã§ãã
æ¬é£è¼ãåè¡æ¬ã«ãªãã¾ããï¼
ãã·ã§ã«è¸ãã«å¹ãï¼AWKå¦æ¹ç®
èè
ï¼æè¤åæ
çºå£²æ¥ï¼2017å¹´1æ31æ¥ï¼ç«ï¼
ä¾¡æ ¼ï¼PODï¼ï¼2,160åï¼ç¨è¾¼ï¼
ä¾¡æ ¼ï¼é»åæ¸ç±ï¼ï¼1,728åï¼ç¨è¾¼ï¼
æ¬æ¸ã«ã¤ãã¦
ãã³ãã³ãã§ãã軽éè¨èªï¼LLï¼ã®å
ç¥ã§ããã£ã¦ãã·ã§ã«ã§ã®ããã¹ããã¼ã¿å¦çã«ã¯ä¾¿å©ã§ææ¾ããªããAWKãã®é
åã¨æ¸ãæ¹ãã·ã§ã«ã³ãã³ãã¨çµã¿åããããã¯ããã¯ï¼ã·ã§ã«è¸ï¼ã解説ã
ãããªã³ããªã³ããã³ãï¼PODï¼ã¨é»åæ¸ç±ã«ã¦ã絶è³çºå£²ä¸ã§ãï¼