星期四, 3月 01, 2007

想在Windows的command line使用Gawk?

想在Windows的command line下使用Gawk?(如下圖示)



你只需要安裝 gawk-3.1.3-2.exe ,安裝完成後在你的使用者變數path中,加上GnuWin32\bin的路徑(如下圖示)。以後就可以輕鬆使用gawk了。:-)


另外,在windows下使用引號的情形,好像也跟gawk手冊上有所不同?這點,還需要確認。

測試指令:
gawk "$1~/a/ {sum=sum+$2+$3;print $1,$2,$3} END {print \"The summation of field 2 and field3 is \"sum}" shipped

測試檔案(shipped):
Jan 13 25 15 115
Feb 15 32 24 226
Mar 15 24 34 228
Apr 31 52 63 420
May 16 34 29 208
Jun 31 42 75 492
Jul 24 34 67 436
Aug 15 34 47 316
Sep 13 55 37 277
Oct 29 54 68 525
Nov 20 87 82 577
Dec 17 35 61 401

Jan 21 36 64 620
Feb 26 58 80 652
Mar 24 75 70 495
Apr 21 70 74 514

沒有留言: