Danの電卓がHPじゃなくてTIなのが意外な感じ。 The idea for the electronic spreadsheet came to me while I was a student at the Harvard Business School, working on my MBA degree, in the spring of 1978. Sitting in Aldrich Hall, room 108, I would daydream. "Imagine if my calculator had a ball in its back, like a mouse..." (I had seen a mouse previously, I think in a demonstration at a conference by Doug Engelbart, and maybe the Alto). And "..imagine if I had a heads-up display, like in a fighter plane, where I could see the virtual image hanging in the air in front of me. I could just move my mouse/keyboard calculator around, punch in a few numbers, circle them to get a sum, do some calculations, and answer '10% will be fine!'" (10% was always the answer in those days when we couldn't do very complicated calculations...)
VisiCalc といえば、出始めの頃に TRS-80 用 を Radio Shack で見せてもらったんだけど、学生だった私には価値がわからなかったなぁ。 まぁ、これに限らず、『なんでこんなコマンドやオプションがあるんだ?』ってのは多い。 使い方じゃなく、なぜそれがあるのかを包括的に解説した本や web site ってありますか。(たとえば多くの unix コマンドを網羅しているとか)
gawk: 331.awk:2: fatal: match() cannot have 3 arguments
match使ってるのにaという3つ目の引数を使ってるから…ってことでしょうか…?
335 :デフォルトの名無しさん:2010/02/28(日) 19:00:04
Q: make spits out errors like Makefile.awk:256: fatal: match() cannot have 3 arguments
A: Your AWK is too old to recreate the Makefile. The build is done based on the distributed Makefile. Everything shall compile successfully though. So if the compile succeeds just ignore such errors, please.
>>339 man gawkより gsub(r, s [, t]) For each substring matching the regular expression r in the string t, substitute the string s, and return the number of substitutions. If t is not supplied, use $0. An & in the replacement text is replaced with the text that was actually matched. Use \& to get a literal &. (This must be typed as "\\&"; see GAWK: Effective AWK Programming for a fuller discussion of the rules for &'s and backslashes in the replacement text of sub(), gsub(), and gen sub().)
$ time mawk 'BEGIN{x=0;for(i=1;i<=1000000;i++){x=x+i};printf("%f\n" ,x)}' 500000500000.000000
real 0m0.131s user 0m0.120s sys 0m0.000s $ time gawk 'BEGIN{x=0;for(i=1;i<=1000000;i++){x=x+i};print x}' 500000500000
real 0m0.289s user 0m0.284s sys 0m0.000s $ time perl -e '$x=0;for($i=1;$i<=1000000;$i++){$x=$x+$i};print $x' 500000500000 real 0m0.379s user 0m0.376s sys 0m0.004s
% time cut -f1 -d, hoge.csv >/dev/null cut -f1 -d, hoge.csv > /dev/null 0.21s user 0.01s system 99% cpu 0.222 total % time awk -F, '{print $1}' hoge.csv >/dev/nulll awk -F, '{print $1}' hoge.csv > /dev/nulll 1.52s user 0.03s system 99% cpu 1.558 total
Within the replacement text s, the sequence \n, where n is a digit from 1 to 9, may be used to indicate just the text that matched the n'th parenthesized subexpression.
length([s]) Returns the length of the string s, or the length of $0 if s is not supplied. Starting with version 3.1.5, as a non-standard exten- sion, with an array argument, length() returns the number of elements in the array.
▼tes09.awk BEGIN{ if (ARGV[1]=="") ARGV[1]="hoge.txt" while (getline < ARGV[1] > 0) print "BEGIN\t"$0 } ARGV[1]=="hoge.txt"{ print "BODY\t"$0 }
★質問 上記スクリプトを引数を付けた場合と付けない場合をそれぞれ実行しました。
▼gawk -f tes09.awk hoge.txt BEGIN arima_yuuichi@example.com BEGIN ooizumi_sadawo@example.com BEGIN taguchi_kenji@example.com BODY arima_yuuichi@example.com BODY ooizumi_sadawo@example.com BODY taguchi_kenji@example.com
▼gawk -f tes09.awk BEGIN arima_yuuichi@example.com BEGIN ooizumi_sadawo@example.com BEGIN taguchi_kenji@example.com
BEGIN { hankaku="0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z " zenkaku="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" } { for (i=0; i<length(hankaku); i+=2) { gsub(substr(hankaku,i+1,1),substr(zenkaku,i+1,2)) } }
class human { property name property sex property age method new(x, y, z) { name = x sex = y age = z } method say() { printf("私は%s。%d歳の%sです。\n",name, age, sex) } } class japanese : human { property name property sex property age method say() { printf("私は%s。%d歳の%sです。国籍は日本です。\n", name, age, sex) } } BEGIN { alice = human.new("アリス", "女", 11) taro = japanese.new("太郎", "男", 15) yuka = japanese.new("由佳", "女", 18) alice.say() taro.say() yuka.say() }
function Human(self,name,sex,age) { self["property___name"] = name self["property___sex"] = sex self["property___age"] = age self["method___say"] = "Human___say" } function Human___say(self) { printf "私は%s。%d歳の%sです。\n", self["property___name"], self["property___age"], self["property___sex"] }
function Japanese(self,name,sex,age) { Human(self,name,sex,age) self["method___say"] = "Japanese___say" } function Japanese___say(self) { printf "私は%s。%d歳の%sです。国籍は日本です。\n", self["property___name"], self["property___age"], self["property___gender"] }
function methodcall(obj,methodname, m) { m = obj["method___" methodname] @m(obj) }
$ cat gettext.po #: gettext.awk:10 msgid "********** Count Prime Number **********" msgstr "========== 素数を数える =========="
#: gettext.awk:14 msgid "2 is a prime number." msgstr "2 は素数です。"
#: gettext.awk:24 msgid "%d is a prime number.\n" "" msgstr "%d は素数です。\n"
$ ls ja_JP/LC_MESSAGES/ gettext.mo
669 :デフォルトの名無しさん:2011/12/22(木) 18:10:02.43
結果はこの通りです。
$ LC_ALL=ja_JP gawk -f gettext.awk 10 ********** Count Prime Number ********** 2 is a prime number. 3 is a prime number. 5 is a prime number. 7 is a prime number.
基本的に一度作って後は必要に応じてコピペだがらな。他には function grep( o, re, p, B, this, a ){ B[0]=0;if(o~"-v"){while((getline v < p)>0){if(!match(v,re))B[B[0]+=1]=v;}return B[0];}; if(o~"-o"){while((getline v < p)>0){a=v;while(match(a,re)){B[B[0]+=1]=substr(a,RSTART,RLENGTH); a=substr(a,RSTART+RLENGTH);}};return B[0];};while((getline v < p)>0){if(match(v,re))B[B[0]+=1]=v;}return B[0]; } なんかも良く使う。grep("-o","pattern","/var/log",data);みたいな感じで。前のはagrep("-v",pattern,B,C)の一部分。 日ごろのメンテでちょっとした手作業じゃめんどいの組むときに、ほぼ数分で組みあがるのが楽なんだよ。 サブプロセスとしてgrep呼び出すのがコストかかる時とか、perlが破損した状況でのリカバリースクリプトとして組んだのが元だけど。 カーネルさえ生きていれば後はawkバイナリ流し込めば使え、shが半分死んでいてもなんとか動くし。
Awk++ http://awk.info/?doc/dsl/awkplusplus.html OO in AWK++ The awk++ language provides object oriented programming for AWK that includes: classes class properties (persistent object variables) methods inheritance, including multiple inheritance
size: 656 byte, supports -o -v option. Array A and B can be the same (NEW) function xagrep( o, re, A, B, this, a, i,k ){ k=0;B[0]=A[0];if(o~"-v"){for(i=1;i<=A[0];i++){if(!match(A[i],re)) B[k+=1]=A[i];}B[0]=k;return k}; if(o~"-o"){B[B[0]+1]=0;for(i=1;i<=A[0];i++){a=A[i];if(i==k){i=i-B[B[0]+1]+1;B[B[0]+1]=k;k=B[0]+2; while(i<=B[B[0]+1]){B[i++]=B[k];delete B[k++];}i=B[B[0]+1];k=i;B[B[0]+1]=0;}while(match(a,re)){ if(i>k){B[k+=1]=substr(a,RSTART,RLENGTH);}else{B[B[0]+1+(B[B[0]+1]+=1)]=substr(a,RSTART,RLENGTH); k++}a=substr(a,RSTART+RLENGTH)}}if(i<k){i=k-i;k=B[0]+1;B[0]=i+B[B[0]+1];while(i<B[0])B[i+=1]=B[k+=1]; while(i<k)delete B[i+=1];}return B[0]}for(i=1;i<=A[0];i++){if(match(A[i],re))B[k+=1]=A[i];}B[0]=k;return k; } これ以上削れるところ無いかな? 高速化+サイズ優先で、変数はできるだけ使う数を少なくとの条件で