Slide 1

Slide 1 text

ϫϯϥΠφʔʹศརͳ ίϚϯυ ˏpapiron

Slide 2

Slide 2 text

ࣗݾ঺հ • Twitter: @papiron • ෱ԬαςϥΠτ։࠵୲౰ • ΠϯϑϥΤϯδχΞͬΆ͍ • WebͳϓνΤϯδχΞͬΆ͍ • ϝϯυ͍͘͞σʔλॲཧ୲౰ • γΣϧͱRubyͱPHP

Slide 3

Slide 3 text

γΣϧܳͱawk • ߦྻࢦ޲ͳσʔλͷѻ͍ • ֤छूܭॲཧ • ਺஋ܭࢉ΍จࣈྻॲཧ AWKΛ࢖͏͜ͱ͕ଟ͍ॲཧ

Slide 4

Slide 4 text

awkͷศར͞ • ೖྗ΍܁Γฦ͠ʹؔ͢Δهड़ෆཁ • IO͔Βreadͱ͔͕ෆཁ • ΞΫγϣϯ͸ຖߦ࣮ߦ • ύλʔϯʹΑΔ৚݅ࢦఆ • ifߏจΛ࢖͏ػձ͕ݮΔ • ศརͳ֤छม਺ • ϑΟʔϧυม਺ʢ$0ɺ$1ɺɺɺʣ • ૊ΈࠐΈม਺ʢNRɺFNRɺNFͳͲʣ ϫϯϥΠφʔΛॻ͖΍͍͢ཁૉ͕ଟ͍

Slide 5

Slide 5 text

awkͬΆ͘ॻ͖͍ͨ ଞͷݴޠͰ΋ awkϥΠΫͳϫϯϥΠφʔΛॻ͖͍ͨ PerlͱRubyͰग़དྷΔ

Slide 6

Slide 6 text

RubyͷawkϞʔυ • ΦϓγϣϯͰawkϥΠΫͳϞʔυʹ • -n ίʔυΛຖߦ࣮ߦ • -a ࣗಈϑΟʔϧυ෼ׂʢ$Fʣ • -l ߦ຤͔ΒվߦจࣈΛऔΓআ͘ • -F ϑΟʔϧυ۠੾Γจࣈࢦఆ • ૊ΈࠐΈม਺ʢ$.ͳͲʣ • -rΦϓγϣϯͰϥΠϒϥϦಡΈࠐΈʢcsvͳͲʣ • BEGIN{}ͱEND{}͕࢖͑Δ

Slide 7

Slide 7 text

$ echo 0 1 2 | ruby -alne 'puts $F[1]' 1 $ cat data.txt user01,175,80 user02,170,65 user03,182,85 $ cat data.txt | ruby -F, -alne 'puts $F[1]' | xargs 175 170 182 $ cat data.txt | ruby -F, -alne 'BEGIN{a=0;b=0}; a+=$F[1].to_i;b+=$F[2].to_i; END{print "਎௕ฏۉ:#{a.to_f/$.} ମॏฏۉ:#{b.to_f/$.}"}' ਎௕ฏۉ:175.66666666666666 ମॏฏۉ:76.66666666666667 RubyͷawkϞʔυ࣮ྫ

Slide 8

Slide 8 text

ϫϯϥΠφʔಛԽίϚϯυ • rbίϚϯυ • https://github.com/thisredone/rb • RubyͷϫϯϥΠφʔಛԽ൛ϥούʔ • opyίϚϯυ • https://github.com/ryuichiueda/opy • PythonͰϫϯϥΠφʔ͸πϥΠ • Πϯσϯτࣗମ͕จ๏ͩͬͨΓ • ্ాձ௕࡞ͷϥούʔ

Slide 9

Slide 9 text

rbίϚϯυ • ඪ४ೖྗ͔Βͷσʔλ͕Ϩγʔό • ௚઀ϝιου͕ॻ͚Δ • 2ͭͷϞʔυ • linesϞʔυ • ೖྗશମΛEnumeratorͱͯ͠ѻ͏ • lineϞʔυʢ-lΦϓγϣϯʣ • 1ߦͣͭStringͱͯ͠ॲཧ͢Δ

Slide 10

Slide 10 text

rbίϚϯυ࣮ྫ # Ϩγʔό͸Enumerator $ seq 3 | rb 'self.inspect' #>:each_line> $ seq 100 | rb grep '/0$/' | xargs 10 20 30 40 50 60 70 80 90 100 # rubyͱൺֱ $ seq 100 | ruby -e 'puts STDIN.each_line.grep(/ 0$/)' | xargs 10 20 30 40 50 60 70 80 90 100 $ seq 10 | rb 'map{|i|i.to_i}.sum' 55 linesϞʔυ

Slide 11

Slide 11 text

rbίϚϯυ࣮ྫ # Ϩγʔό͸ೖྗ֤ߦͷจࣈྻ $ seq 3 | rb -l 'self.inspect' | tr '\n' ' ' "1" "2" "3" $ echo 0,1,2 | rb -l 'split(",")[1]' 1 # Rubyͱൺֱ $ echo 0,1,2 | ruby -ne 'puts $_.split(",")[1]' 1 $ seq 100 | xargs -n 10 | rb -l split.last | xargs 10 20 30 40 50 60 70 80 90 100 lineϞʔυ

Slide 12

Slide 12 text

rbͰग़དྷͳ͍͜ͱ • Φϓγϣϯ͸࢖͑ͳ͍ • -FͰ۠੾Γจࣈࢦఆ͸ग़དྷͳ͍ • -rͰϥΠϒϥϦಡΈࠐΈ͸ग़དྷͳ͍ • ϑΟʔϧυͷࣗಈ෼ׂ • BEGINͱEND

Slide 13

Slide 13 text

opyͷࢿྉ PythonΛίϚϯυϥΠϯͰ࢖͍͍ͨͷͰopyͱ͍͏ίϚϯυΛ࡞ͬͨ https://b.ueda.tech/?post=20190908_opy ࣗ࡞ίϚϯυʢopyʣΛbrewͱsnapʹରԠͨ͠ https://b.ueda.tech/?post=20190911_opy opyʹjoin, dropjoinΛ࣮૷ https://b.ueda.tech/?post=20190916 opyͰPythonͷSciPyͱNumPyΛϫϯϥΠφʔͰ࢖͏࣮ݧ https://b.ueda.tech/?post=20190929_opy ্ా͞ΜϒϩάΛࢀর

Slide 14

Slide 14 text

͋͑ͯawkΛ࢖͏ར఺ • େମೖ͍ͬͯΔ • ௥ՃΠϯετʔϧෆཁͳ৔߹͕ଟ͍ • ॲཧ͕ߴ଎ • େن໛ͳςΩετσʔλͷॲཧʹ