Save 37% off PRO during our Black Friday Sale! »

Perlを中心としたワンライナーあれこれ

 Perlを中心としたワンライナーあれこれ

YAPC::Okinawa 2018 ONNASON B会場
(Keynote版に修正しました)

58758490105b10d8cee797179bc0d1cc?s=128

Shigeki SUGAI

March 03, 2018
Tweet

Transcript

  1. 1FSMΛத৺ͱͨ͠ w !UFDLM w  w :"1$0LJOBXB0//"40/ ϫϯϥΠφʔ͋Ε͜Ε

  2. :"1$0LJOBXB 0//"40/

  3. ԭೄ࠷ߴͰ͢ʂ

  4. :"1$0LJOBXB࠷ߴͰ͢ʂʂ

  5. ͢Έ·ͤΜɼۓுͯ͠·͆͢

  6. ࠓ೔ͷ૝ఆର৅ w ීஈϫϯϥΠφʔΛ͋·Γ࢖͍ͬͯͳ͍ํ w $6*$-* ίϚϯυϥΠϯ ʹෆ׳Εͳํ w 1FSMΛ͋·Γ࢖ͬͯͳ͍ɺ͜Ε͔Β࢝Ί͍ͨํ

  7. ໨࣍ w ࣗݾ঺հɾձࣾ঺հ w ϫϯϥΠφʔͷྑ͞ w 6/*9ͱ͍͏ߟ͑ํ w 1FSMͷओͳίϚϯυϥΠϯ w

    ࣮ࡍͷ࣮ྫू w ʜͳͲΛബ͘঺հ͠·͢
  8. ࣗݾ঺հ w 4IJHFLJ46("* !UFDLM  w γʔαʔגࣜձࣾ   w

    αʔόαΠυΤϯδχΞ %FW0QT w ࠷ۙ͸ͳ͔ͳ͔ίʔυΛॻ͕࣌ؒ͘ʜ w ΒʔΊΜ໺࿠ w *OHSFTT 3FTJTUBODF "  w ϙέϞϯ(0 5-
  9. ձࣾ঺հ γʔαʔגࣜձࣾ

  10. ձࣾ঺հ w 4FFTBBϒϩά w 4FFTBBXJLJ w ͨ͠Β͹ܝࣔ൘ w #PPN"QQ(BNFT w

    ଞʹ΋ϒϩάγεςϜͷ0&.ɾεϚϗΞϓϦ։ൃ ͳͲ΍ͬͨΓ͍ͯ͠·͢
  11. ΄ͱΜͲ1FSMͰಈ͍ͯ· ͢ʂʂʂʂʂ̍

  12. ձࣾ঺հ w ࡢ೥͸!YUFUTVKJ͞Μʹ1FSMೖֶࣜاۀग़ு ൛ JOTFFTBB Λճ΋։࠵͍͖ͯͨͩ͠·͠ ͨʂ w IUUQQPTUUFUTVKJKQQFSM FOUSBODFTFSWJDFGPSDPNQBOZ

    w ͜ͷ#ձ৔ͷ࣍ͷηογϣϯͳͷͰָ͓͠Έ ʹʂʂ
  13. ʮγʔαʔʯ͍ͬͯ͏͔Βʹ ͸ɺ౰વԭೄʹؔ܎͕ʁ

  14. ޙͰݸਓతʹฉ͍͍ͯͩ͘͞ʜ

  15. ຊ୊

  16. ϫϯϥΠφʔͱ͸ w ʮϫϯϥΠφʔʯͱ͸ɺͨͬͨߦ͚ͩͷϓϩά ϥϜͰ͢ɻ1FSM΍3VCZΛ࢖͏ͱɺߦ͚ͩͰ΋͔ͳ Γͷ࢓ࣄ͕Ͱ͖·͢ɻ w ϓϩάϥϜΛॻ͖͍͕ͨɺΤσΟλΛىಈ͢Δ΄ Ͳͷखؒ͸͔͚ͨ͘ͳ͍ɺͱ͍͏ͱ͖ʹҖྗΛൃش ͠·͢ɻ w

    IUUQMDMJOVYPSKQMDGBMMTT EFUBJMIUNMQFSMSVCZ
  17. ೔ຊޠͰݴ͏ͱ͜Ζͷɺ Ұߦ໺࿠

  18. ϫϯϥΠφʔͷϝϦοτ

  19. ϫϯϥΠφʔͷϝϦοτ w ͱʹ͔͘࢓ࣄ͕ૣ͍ʂ w ͍͍ͪͪΤσΟλΛ্ཱͪ͛Δඞཁ͢Βͳ͍ w ಛఆͷϓϩάϥϜݴޠ஌ࣝʹؔΘΒͳ͍ w ίϚϯυϥΠϯ͔Β࢖͑ΔύλʔϯΛ֮͑Ε͹֮͑Δ΄ ͲɺԠ༻ൣғ͕޿͕Δ

    w ΤϯδχΞͱͯ͠΍͍ͬͯ͘ͳΒɺࠓޙ΋ͣͬͱ࢖͑Δ ஌ࣝʹͳΔ
  20. ϫϯϥΠφʔΛ ͲΜͳ࣌ʹ࢖͏ͷʁ

  21. ϫϯϥΠφʔΛͲΜͳ࣌ʹ࢖ ͏ͷʁ w αʔόӡ༻ɾো֐ൃੜ࣌ͷϩάղੳ w ୯७ͳόάͷใࠂ࣌ w ଞਓʹઆ໌͢Δͱ͖ʹ΋ߦͰઆ໌͕෇͘ w ϓϧϦΫͳͲͷόάใࠂʹ͸ɺ࠷΋୹͘࠷

    খݶͰ࠶ݱͰ͖ΔίʔυΛݟͤΔͷ͕࠷΋ ૣ͍
  22. ϫϯϥΠφʔΛͲΜͳ࣌ʹ࢖ ͏ͷʁ w εΫϦϓτΛॻ͘·Ͱ΋ͳ͍ௐࠪґཔܥͷ࡞ۀ w େྔͷσʔλ͔Βಛఆͷσʔλ͚ͩΛநग़͠ ͍ͨ w ߦ͚ͩͳͷͰɺ࢖͑ΔཁૉΛվมͯ͠खݩͰ खܰʹࢼͤΔ

    w γΣϧܳ
  23. ʜͯ͞ɺϫϯϥΠφʔͷ࿩ͷ ్தͰ͕͢

  24. 6/*9ͱ͍͏ߟ͑ํͦͷઃܭ ࢥ૝ͱ఩ֶ w ͱ͍͏ຊΛ͝ଘ஌Ͱ͠ΐ͏͔ʁ

  25. 6/*9ͱ͍͏ߟ͑ํ w ൃץ͔Β೥Ҏ্ܦա͍ͯͯ͠ݹయతͳײ͡ʹͳ ͍ͬͯ·͕͢ɺࠓ͔ΒͰ΋े෼ಡΉՁ஋͕͋Δ໊ ஶͰ͢ w ٕज़ॻͱ͍͏ΑΓ఩ֶॻ w ϓϩάϥϛϯάΛֶͼ࢝ΊͨࠒʹಡΜͰ͓͚ ͹ɻɻ

    w 6/*9ͱ͍͏ߟ͑ํʕͦͷઃܭࢥ૝ͱ఩ֶ
  26. 6/*9ͱ͍͏ߟ͑ํ w ೥͔Βɺશ͘಺༰͕มΘΒͣࠓ΋ചΕଓ͚ ͍ͯ·͢ ೔ຊޠ൛ɺݪஶ͸೥ࠒ

  27. ͭͷఆཧ w εϞʔϧŋΠζŋϏϡʔςΟϑϧ খ͍͞΋ͷ͸ඒ͠ ͍  w ҰͭͷϓϩάϥϜʹ͸Ұͭͷ͜ͱΛ͏·͘΍ΒͤΔ w Ͱ͖Δ͚ͩૣ͘ࢼ࡞͢Δ

    w ޮ཰ΑΓҠ২ੑΛ༏ઌ͢Δ w ਺஋σʔλ͸"4$**ϑϥοτϑΝΠϧʹอଘ͢Δ
  28. ͭͷఆཧ w ιϑτ΢ΣΞΛᑏࢠʢςίʣͱͯ͠࢖͏ w γΣϧεΫϦϓτʹΑͬͯᑏࢠͷޮՌͱҠ২ੑ ΛߴΊΔ w ա౓ͷର࿩తΠϯλϑΣʔεΛආ͚Δ w ͢΂ͯͷϓϩάϥϜΛϑΟϧλͱͯ͠ઃܭ͢Δ

  29. 6/*9ͱ͍͏ߟ͑ํ w ҰͭͷϓϩάϥϜͰͳΜͰ΋ग़དྷΔΑ͏ʹػೳΛ௥Ճ͍ͯ͠ ͘ͷͰ͸ͳ͘ɺ w ͨͬͨҰͭͷࣄ͔͠Ͱ͖ͳ͍খ͞ͳϓϩάϥϜɾίϚϯυΛ ͏·͘૊Έ߹ΘͤͯςίͷޮՌΛग़ͨ͠΄͏͕ɺང͔ʹޮ཰ ྑ͘໨తΛୡ੒Ͱ͖ΔΑ͏ʹͳΔ w ύΠϓΛհ͢Δ͜ͱʹΑͬͯɺখ͞ͳϓϩάϥϜಉ͕࢜͢΂

    ͯ૬ޓʹ࿈ܞͰ͖Δ w ૄ݁߹Λྑ͠ͱ͢ΔϚΠΫϩαʔϏεతͳߟ͑ํͱ΋௨͡Δ
  30. 6/*9ͱ͍͏ߟ͑ํ w ௒ͬ͘͟Γ͍͏ͱɺ w େن໛ͳϓϩάϥϜ΍ಛఆͷόΠφϦͷΑ͏ͳ σʔλΑΓ΋ɺϓϨʔϯςΩετͰɺখ͍͞ϓϩ άϥϜ܈Λ͏·͘૊Έ߹ΘͤΔ͜ͱʹΑͬͯΏ Δ͘࿈ܞͤ͞·͠ΐ͏ɺͱ͍͏ߟ͑ํ

  31. 6/*9ͷ఩ֶΛݟͨͱ͜ΖͰʜ w ϫϯϥΠφʔͷ࿩ʹ໭Γ·͠ΐ͏

  32. ԿނϫϯϥΠφʔͰ 1FSMͳͷ͔ʁ

  33. ԿނϫϯϥΠφʔͰ1FSMͳͷ͔ʁ w ߴ͍Ҡ২ੑ w 1FSM͸ޓ׵ੑ͕ߴ͍ w BXLͱ͔ͩͱ04ʹΑͬͯ͸ඍົͳҧ͍͕͋ͬͨΓɺ w γΣϧ΋#PVSOF4IFMMܥͱ$4IFMMܥʹΑͬͯ΋ඍົʹҧ ͍͕͋ͬͨΓ͢Δ

    w 1FSM͸େ఍ͷ04ʹೖ͍ͬͯΔ w ڧྗͳਖ਼نදݱ
  34. ԿނϫϯϥΠφʔͰ1FSMͳͷ͔ʁ w 1FSMʹݶΒͣɺ"XLͰ΋TFEͰ΋3VCZͰ΋ɺ ࣗ෼ͷ஌͍ͬͯΔൣғͰࣗ༝ʹ࢖͑͹े෼ w ΍Γํ͸ͻͱͭ͡Όͳ͍ w Ͱ͕͢ɺ΍ͬͺΓ1FSMΛ஌͍ͬͯΔͱָʹͳΓ ·͢Αɺͱ͍͏ྫΛ঺հ͠·͢

  35. 1FSMͷओͳίϚϯυϥΠϯΦ ϓγϣϯʢεΠονʣ w ʜ͞Βͬͱྲྀ͠·͢

  36. F w Fॲཧɹ w ͢΂ͯ͸͔͜͜Βɻ w ޙଓͷॲཧΛίϚϯυϥΠϯͷϓϩάϥϜͱ͠ ࣮ͯߦ͠·͢ɻ $ perl

    -e 'print "Hello World!"'
  37. &ॲཧ w ɹ w lFzͱಉ༷ʹৼΔ෣͍·͕͢ɺ w VTFGFBUVSFbBMM`΍ɺ w VTFW w

    ͱಉ౳ͷޮՌ͕͋Γ·͢ɻ # say ͕࢖͑ΔΑ͏ʹͳΔʂ $ perl -E 'say "Hello World!"'
  38. M w ೖྗߦΛDIPNQͯ͘͠Εͯɺ·ͨQSJOU࣌ʹվ ߦΛ௥Ճͯ͘͠Ε·͢ɻ # say Ͱ͸ͳ͍ͨΊɺվߦίʔυؚ͕·Εͳ͍ $ perl -e

    'print "Hello World!"' Hello World!$ # -l ͍ͯ͠ΔͷͰɺվߦͯ͘͠ΕΔ $ perl -le 'print "Hello World!"' Hello World! $
  39. O w ɹೖྗσʔλͷ֤ߦΛॲཧ͠·͢ɻ while (<>) { ॲཧ; }

  40. B $ head -n 3 KEN_ALL.CSV | nkf -w 01101,"060

    ","0600000","ϗοΧΠυ΢","αοϙϩγνϡ΢Φ΢Ϋ","ΠΧχέΠαΠΨφΠόΞΠ","๺ւಓ","ࡳຈࢢதԝ۠","ҎԼʹ ߹",0,0,0,0,0,0 01101,"064 ","0640941","ϗοΧΠυ΢","αοϙϩγνϡ΢Φ΢Ϋ","ΞαώΨΦΧ","๺ւಓ","ࡳຈࢢதԝ۠","Ѵέٰ",0,0,1,0,0 01101,"060 ","0600041","ϗοΧΠυ΢","αοϙϩγνϡ΢Φ΢Ϋ","ΦΦυΦϦώΨγ","๺ւಓ","ࡳຈࢢதԝ۠","େ௨౦",0,0,1, # ۠੾ΓจࣈΛ "," ʹมߋ͢Δ͜ͱͰCSVʹରԠ $ head -n 3 KEN_ALL.CSV | nkf -w | perl -F, -lane 'print $F[3]' "ϗοΧΠυ΢" "ϗοΧΠυ΢" "ϗοΧΠυ΢" w BXLͬΆ͍࢖͍৺஍ʹͳΓ·͢ɻ w O΍QͱҰॹʹ༻͍ΔͱɺࣗಈͰTQMJUϞʔυʹͳΓɺ഑ྻ!'ʹ஋͕୅ೖ͞Ε·͢ɻ w 'Λ࢖͏ͱ۠੾ΓจࣈΛมߋͰ͖·͢ɻ
  41. .Ϟδϡʔϧ໊ w ίϚϯυϥΠϯ͔Β1FSMϞδϡʔϧΛ࢖༻͢Δ͜ ͱ͕Ͱ͖·͢ɻ w ͭ·ΓͳΜͰ΋ग़དྷ·͢ɻ # LWPͰHTMLΛऔಘͯ͠grep $ perl

    -MLWP::Simple -e 'getprint "http://www.perl.org/"' | grep title <title>The Perl Programming Language - www.perl.org</title> # strftime ͷ %Y ͱ %G Ͱҧ͏ڍಈΛ֬ೝ $ perl -MTime::Piece -E \ 'say Time::Piece->strptime("2014-12-30", "%Y-%m-%d")->strftime("%Y")' 2014 $ perl -MTime::Piece -E \ 'say Time::Piece->strptime("2014-12-30", "%Y-%m-%d")->strftime("%G")' 2015
  42. .0%FQBSTF w #%FQBSTFίΞϞδϡʔϧ w ϫϯϥΠφʔͩͱҰݟ෼͔Γʹ͍͘Α͏ͳίʔυ΋ɺ w .0%FQBSTFΛ࢖͏͜ͱʹΑͬͯίϚϯυϥΠϯͰ͸ͳ͘ɺεΫϦϓτͩ ͬͨΒͲ͏͍͏ίʔυΛ࣮ߦ͍ͯ͠Δ͔Λ֬ೝ͢Δࣄ͕Ͱ͖·͢ɻ # ϫϯϥΠφʔͷίϚϯυϥΠϯΛ΋͠εΫϦϓτͰॻ͍ͨΒͲ͏ͳΔ͔Λ

    -MO=Deparse Ͱදࣔ $ head -n 3 KEN_ALL.CSV | nkf -w | perl -MO=Deparse -F, -lane 'print $F[3]' BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined($_ = readline ARGV)) { chomp $_; our @F = split(/,/, $_, 0); print $F[3]; } -e syntax OK
  43. ϫϯϥΠφʔͰ໾ʹཱͭ1FSMͷ ಛघม਺ w ɿݱࡏͷߦ൪߸ w  ɿQSJOUҾ਺ͷηύϨʔλ w ɿೖྗʢPQFOʣ࣌ͷߦ۠੾Γจࣈ w

    aɿग़ྗʢQSJOUʣ࣌ͷߦ۠੾Γจࣈ w ɿΤϥʔͷ಺༰
  44. ΋ͬͱৄ͘͠ w QFSMίϚϯυϥΠϯʹ͍ͭͯ΋ͬͱ஌Γ͍ͨਓ͸ w QFSMEPDQFSMSVO w ΋͘͠͸೔ຊޠ༁΋͋Γ·͢ w IUUQQFSMEPDKQEPDTQFSM QFSMSVOQPE

  45. ϫϯϥΠφʔͷࣄྫ঺հ

  46. ಛఆจࣈྻΛஔ׵͍ͨ͠

  47. ·ͣ͸࠷΋Α͋͘Δ΍͔ͭΒ # tsvΛcsvʹஔ׵ $ perl -p -e 's/\t/,/' /tmp/hoge.tsv >

    /tmp/hoge.csv # ର৅σΟϨΫτϦ಺ͷ htmlϑΝΠϧதͷ 2017- Λ 2018- ʹஔ׵ $ find target_dir -type f -name '*.html' | \ xargs perl -pi -e 's/2017-/2018-/g'
  48. ͪΐͬͱͨ͠$47ͷ 46.Λूܭ͍ͨ͠

  49. ͪΐͬͱͨ͠$47ͷ46.Λू ܭ͍ͨ͠ # ͜ΜͳCSV͕͋Δͱͯ͠ɺ֤ߦͷֹۚͷ߹ܭΛٻΊ͍ͨ $ echo -e "ϥʔϝϯ,690\nຯۄ,100\nᰤࢠ,300" ϥʔϝϯ,690 ຯۄ,100

    ᰤࢠ,300 # ֹۚͷྻΛՃࢉ͠ɺ END {} Λ࢖ͬͯ࠷ޙʹֹۚͷ߹ܭ஋͚ͩग़ྗ $ echo -e "ϥʔϝϯ,690\nຯۄ,100\nᰤࢠ,300" | \ perl -F, -lane '$sum += $F[1]; END {print $sum}' 1090
  50. खݩͷϑΝΠϧΛ ٯॱʹग़ྗ͍ͨ͠

  51. खݩͷϑΝΠϧΛٯॱʹग़ྗ ͍ͨ͠ w ͜͏͍͏$47͕͋Δͱ͠·͢ # ͜ΕΛٯॱʹ(߱ॱͰ)ग़͍ͨ͠ $ cat /tmp/yapc.csv 2016.12.10,YAPC::Hokkaido

    2016 SAPPORO 2017.3.4,YAPC::Kansai 2017 OSAKA 2017.7.1,YAPC::Fukuoka 2017 HAKATA 2018.3.3,YAPC::Okinawa 2018 ONNASON
  52. खݩͷϑΝΠϧΛٯॱʹग़ྗ ͍ͨ͠ w ΋͠AUBDAίϚϯυ ADBUAͷٯ൛ Λ஌͍ͬͯΕ͹ # Linux $ tac

    /tmp/yapc.csv 2018.3.3,YAPC::Okinawa 2018 ONNASON 2017.7.1,YAPC::Fukuoka 2017 HAKATA 2017.3.4,YAPC::Kansai 2017 OSAKA 2016.12.10,YAPC::Hokkaido 2016 SAPPORO
  53. खݩͷϑΝΠϧΛٯॱʹग़ྗ ͍ͨ͠ w ͔͠͠ɺUBDίϚϯυ͸-JOVYʹ͔͠ೖ͍ͬͯ·ͤΜɻ w .BD #4%ܥ Ͱ͸ɺ୅ΘΓʹAUBJMSA SFWFSTF ͕͋Γ·͢ɻ

    # Mac(BSDܥ) $ tail -r yapc.csv 2018.3.3,YAPC::Okinawa 2018 ONNASON 2017.7.1,YAPC::Fukuoka 2017 HAKATA 2017.3.4,YAPC::Kansai 2017 OSAKA 2016.12.10,YAPC::Hokkaido 2016 SAPPORO
  54. खݩͷϑΝΠϧΛٯॱʹग़ྗ ͍ͨ͠ w -JOVYͰ΋.BDͰ΋ಉ͡ͷΛ࢖͍͍ͨͰ͢ΑͶʂ w ϙʔλϏϦςΟΛߟ͑Δͱɺ΍ͬͺΓ1FSM # ϑΝΠϧͷߦΛٯॱʹग़ྗ $ perl

    -e 'print reverse <>' /tmp/yapc.csv 2018.3.3,YAPC::Okinawa 2018 ONNASON 2017.7.1,YAPC::Fukuoka 2017 HAKATA 2017.3.4,YAPC::Kansai 2017 OSAKA 2016.12.10,YAPC::Hokkaido 2016 SAPPORO
  55. ΞΫηεϩάௐࠪܥ

  56. αʔϏε͕ٸʹॏ͘ͳͬͨ࣌ ʢো֐࣌ͷରԠʣ w NBDLFSFMͳͲͷ؂ࢹπʔϧͷάϥϑͳͲΛݟΔ ͱͱ΋ʹɺΞϥʔτ͕ಧ͍ͨॠؒʹ·ͣ͸ϩά ΛݟΔ w ͕͜͜ϫϯϥΠφʔͷ࠷΋ಘҙͳͱ͜Ζ w ࣍ϖʔδҎ߱͸$PNCJOFE-PHϑΥʔϚοτ

    ͷ૝ఆͱ͠·͢
  57. ΞΫηεݩͷ*1্ҐΛ஌Γ͍ͨ # ௚ۙͷIP্ҐΛ߱ॱʹදࣔ $ tail -500000 access_log | perl -lane

    'print $F[0]' | sort | \ uniq -c | sort -nr | head -3 72802 11.22.33.44 527 222.33.44.55 521 3.4.5.6 # `perl -lane 'print $F[0]'` ͸ɺ # `awk '{print $1}'` Ͱ΋ɺ # `cut -f 1 -d ' '` Ͱ΋OK
  58. ΞΫηεݩͷϢʔβʔΤʔδΣ ϯτ্ҐΛ஌Γ͍ͨ

  59. ΞΫηεݩͷϢʔβʔΤʔδΣ ϯτ্ҐΛ஌Γ͍ͨ # UserAgent্ҐΛ߱ॱʹιʔτ $ tail -500000 access_log | perl

    -F'"' -lane 'print $F[5]' | \ sort | uniq -c | sort -nr | head -4 756981 Mozilla/5.0 (compatible; EvilBot/3.0; +http://www.example.com/evilbot.html) 7192 Mozilla/5.0 (compatible; Normalbot/2.1; +http://www.example.com/bot.html) 1277 Mozilla/5.0 (compatible; smallbot/2.0; +http://www.example.com/smallbot.htm) 253 Mozilla/5.0 (compatible; minbot/2.0; +http://www.example.com/min.htm)
  60. Τϥʔܥͷո͍͠εςʔλε ίʔυͷϩάΛ؂ࢹ͍ͨ͠

  61. σϓϩΠޙ͸Τϥʔܥͷϩά ͚ͩʹ஫ࢹ͍ͨ͠ # ΤϥʔܥͷϩάΛࡶʹtail $ tail -F access_log | awk

    '$9 !~ /200|301|302|304/ {print}' # perlͷ৔߹ $ tail -F access_log | perl -lane 'print if $F[8] !~ /200|301|302|304/'
  62. ෼୯ҐʹΞΫηε਺ Λूܭ͍ͨ͠

  63. ෼୯ҐʹΞΫηε਺Λूܭ͍ͨ͠ w ಛఆͷ࣌ؒଳ͚ͩେྔʹΫϩʔϧ͕དྷ͍ͯΔ͔Ͳ͏͔͕Θ͔Δ # ෼୯ҐͷϦΫΤετ਺ $ cat access_log | perl

    -lne 'm{2017:(\d+):(\d+)} and print "$1:$2"' | \ sort | uniq -c | head 6559 05:06 5642 05:07 89774 05:08 5592 05:09 4010 05:10
  64. *&ͷ֤8JOEPXTຖͷ ׂ߹Λ஌Γ͍ͨ

  65. *&ͷ֤8JOEPXTຖͷׂ߹Λ ஌Γ͍ͨ w 6OEFSTUBOEJOHVTFSBHFOUTUSJOHT *OUFSOFU &YQMPSFS c.JDSPTPGU%PDT # IE11ͷUAจࣈྻͰɺWindows NTͷޙΖͷ਺ࣈΛൈ͖ग़͢

    $ head -500000 access_log | egrep 'rv:11\.0' | \ perl -lane '/Windows NT ([\d.]+)/ && print $1' | \ sort | uniq -c | sort -nr | head 11160 6.1 # Windows 7 8006 10.0 # Windows 10 5769 6.3 # Windows 8.1 12 6.2 # Windows 8 1 5.1 # Windows XP
  66. ಛఆͷ6"͕શମʹ઎ΊΔൺ཰ ʢϒϥ΢βγΣΞʣΛ஌Γ͍ͨ

  67. ಛఆͷ6"͕શମʹ઎ΊΔൺ཰ ʢϒϥ΢βγΣΞʣΛ஌Γ͍ͨ # Firefoxͷશମͷൺ཰ $ cat access_log | perl -lane

    '/Firefox/i && $cnt++ ; {print ($cnt / $. ) } ' 0.0734 # IE11ͷൺ཰ $ cat access_log | perl -lane '/rv:11\.0/ && $cnt++ ; {print ($cnt / $. ) } ' 0.065 $. ͷಛघม਺ʢݱࡏͷߦ਺Λද͢ʣΛ࢖͏ͱָͰ͢
  68. ো֐࣌ͷϩάௐࠪʹ͍ͭͯͷิ଍ w ো֐࣌ͷରԠʹ͍ͭͯɺͦ΋ͦ΋؂ࢹ߲໨Λࣄલʹઃఆ͓ͯ͠ ͘͜ͱ͕ॏཁ w ো֐൑໌ޙʹ·ͣͲ͔͜Βಈ͘ͷ͔ w CPUͳͲͷ֎తཁҼ͔ɺͦΕͱ΋಺తཁҼ͔ w ໰୊੾Γ෼͚࣌ͷॳಈௐࠪ࣌Ͱ͸ੜϩάௐࠪͷεϐʔυ

    ͕࠷΋ॏཁͱͳΔ w ϫϯϥΠφʔͰͷϩάௐࠪ͸ɺ͋͘·Ͱ΋؂ࢹπʔϧͷิ׬ͱ ͯ͠ɺ྆ํॏཁͰ͢
  69. ͦͷଞࡶଟͳϫϯϥΠφʔ

  70. େྔ63-͔ΒϦϯΫ੾Ε΍ε ςʔλείʔυΛௐ΂͍ͨ

  71. େྔ63-͔ΒϦϯΫ੾Ε΍ε ςʔλείʔυΛௐ΂͍ͨ # େྔͷURLͷςΩετ͔ΒɺεςʔλείʔυΛࡶʹνΣοΫ͢Δ $ cat /tmp/url.txt | xargs -t

    -L1 -P1 curl -X GET -I -s | grep HTTP curl -X GET -I -s mojolicious.org HTTP/1.1 200 OK curl -X GET -I -s mojolicious.io HTTP/1.1 301 Moved Permanently curl -X GET -I -s mojocasts.com HTTP/1.1 302 Found curl -X GET -I -s http://example.com/not_found.txt HTTP/1.1 404 Not Found
  72. େྔͷϑΝΠϧ͕ೖͬͨσΟϨ ΫτϦΛঃʑʹ࡟আ͢Δ

  73. େྔͷϑΝΠϧ͕ೖͬͨσΟϨ ΫτϦΛঃʑʹ࡟আ͢Δ w Ұ౓ʹ௚Լ͔Β࡟আͯ͠͠·͏ͱ*0ෛՙ͕͔͔ΔͷͰʜ w ͳ͓ɺYBSHT͔Βͷ࡟আʹ͍ͭͯ͸ɺQFSMΛ࢖ͬͨํ͕ޮ཰͕ྑ͍͜ͱ͕ଟ͍ͱ஄͞Μͷϒ ϩάʹৄ͍͠આ໌͕͋Γ·͢ɻ w IUUQCMPHMJWFEPPSKQEBOLPHBJBSDIJWFTIUNM #

    σΟϨΫτϦΛ2֊૚෼ԼΓͯগͣͭ͠࡟আ͍ͯ͘͠ $ time find dir/ -type d -mtime +100 -mindepth 2 -maxdepth 2 | \ xargs -r -n 1 -t rm -rf
  74. +40/ΛίϚϯυϥΠϯ͔Β࢖͏

  75. +40/ΛίϚϯυϥΠϯ͔Β࢖͏ $ echo -e '{"items":[{"name":"ϥʔϝϯ","price":690},{"name":"ຯۄ","price":100},{"name":"ᰤࢠ","price":300}]}' \ | jq { "items":

    [ { "name": "ϥʔϝϯ", "price": 690 }, { "name": "ຯۄ", "price": 100 }, { "name": "ᰤࢠ", "price": 300 } ] }
  76. +40/ΛίϚϯυϥΠϯ͔Β࢖͏ w KRίϚϯυͰඞཁͳཁૉͷΈΛநग़ $ echo -e '{"items":[{"name":"ϥʔϝϯ","price":690},{"name":"ຯۄ","price":100},{"name":"ᰤࢠ","price":300}]}' | \ jq

    -r '.items[].price' 690 100 300 $ echo '{"items":[{"name":"ϥʔϝϯ","price":690},{"name":"ຯۄ","price":100},{"name":"ᰤࢠ","price":300}]}' | \ jq -r '.items[].price' | perl -lane '$sum += $F[0]; END {print $sum}' 1090
  77. αʔό؅ཧ

  78. αʔό؅ཧ w .BDLFSFMΛ࢖͍ͬͯΔέʔε w $-*πʔϧNLS w IUUQTNBDLFSFMJPKBEPDTFOUSZBEWBODFEDMJ # ϗετҰཡΛϦετ $

    mkr hosts --service yapc --role app | jq -r '.[].name' yapc-app1 yapc-app2 yapc-app3 # ҰׅͰεςʔλε͕poweroff͍ͯ͠Δ΋ͷΛநग़ $ for x in $(seq 1 3) ; do mkr hosts -n yapc-app$x --status poweroff ; done # 1୆ͣͭWEB͔Βୀ໾ͤ͞Δͷ͸େมͳͷͰɺϗετΛҰׅͰୀ໾ͤ͞Δ $ for x in $(seq 1 3) ; do mkr hosts -n yapc-app$x | jq -r '.[].id' | xargs mkr retire ; done
  79. (SBQI2-

  80. (SBQI2- # ϦϙδτϦ಺ͷOpenதͷissueҰཡΛऔಘ $ curl -s -H "Authorization: bearer $TOKEN"

    -X POST -d \ '{"query":"{ organization(login: \"plack\") { \ repository(name: \"Plack\") { issues(last:3, states:OPEN) { \ edges{ node{ url title } } } } } }"' https://api.github.com/graphql | \ jq -r '.data.organization.repository.issues.edges[].node | .url' https://github.com/plack/Plack/issues/544 https://github.com/plack/Plack/issues/562 https://github.com/plack/Plack/issues/570 # GraphQL Ͱ github organizationʹॴଐ͍ͯ͠ΔϝϯόʔҰཡΛग़ྗ͢Δ $ curl -s -H "Authorization: bearer $TOKEN" -X POST -d \ '{"query":"{ organization(login: \"org_name_hoge\") \ { members(first: 100) { edges { node { login } } } } }","variables":"{}","operationName":null}' https://api.github.com/graphql | \ jq -r '.data.organization.members.edges[].node.login' | sort | head fukuoka hokkaido kansai okinawa
  81. EPDLFS

  82. EPDLFS # ఀࢭ͍ͯ͠ΔίϯςφΛ࡟আ docker ps -a | grep [E]xited |

    awk '{print $1}' | xargs -n 1 docker rm # <none> ͷΠϝʔδΛҰׅ࡟আ͍ͨ͠ $ docker images -a | perl -lane '/<none>/ && print $F[2]' | xargs docker rmi
  83. .Z42-ͰεϩʔΫΤϦʔϩάΛ ग़ͨͯ͘͠΋ઃఆมߋग़དྷͳ͍࣌

  84. .Z42-ͰεϩʔΫΤϦʔϩάΛ ग़ͨͯ͘͠΋ઃఆมߋग़དྷͳ͍࣌ # ਂԕͳΔཧ༝ʹΑΓslow_query_logΛઃఆग़དྷͳ͍৔߹ͷ࢑ఆાஔ… # whileΛ࢖ͬͯແݶʹॏ͍ΫΤϦΛϑΝΠϧʹग़ྗ $ while ``;do mkdir

    -p /tmp/slow_log_dbxxx/`date +%Y%m%d` ; \ mysql -urepl -hxxx -e 'show full processlist' | grep -v Sleep | \ egrep -v 'Binlog|Connect' | awk '$6 > 2' | grep -v '^Id' | \ sort -nr -k 6 | head -5 2>&1 | \ tee -a /tmp/slow_log_dbxxx/`date +%Y%m%d/%H%M_slow.txt` ;sleep 3;done;
  85. ૉ਺Λ਺͑ͯམ͖͍ͪͭͨ࣌

  86. ૉ਺Λ਺͑ͯམ͖͍ͪͭͨ࣌ w ͍ΘΏΔγΣϧܳ w ۀ຿Ͱ໾ཱ͔ͭͲ͏͔͸ஔ͍͓͍ͯͯɺɺ $ perl -e 'print "མͪͭ͘Μͩ…ૉ਺Λ਺͑ͯམͪͭ͘Μͩ…

    "; \ for(1 .. 100){print "$_…" if $_==2 || 2**($_-1) %$_==1}' མͪͭ͘Μͩ…ૉ਺Λ਺͑ͯམͪͭ͘Μͩ… 2…3…5…7…11…13…17…19…23…29…31…37…41…43…47…53…59…61…67…71…73…79…
  87. खܰʹεΫϨΠϐϯά

  88. खܰʹεΫϨΠϐϯά w εΫϨΠϐϯάͱ͍͑͹8FC4DSBQFSͰ͕͢ɺ ϫϯϥΠφʔͰ΍Δʹ͸ͪΐͬͱ͖͍ͭʜ w ɹͦ͜Ͱɺ1FSMͰ༗໊ͳ8FCΞϓϦέʔγϣϯϑϨ ʔϜϫʔΫͷ.PKPMJDJPVT͕͋Γ·͕͢ɺͦ͜ʹؚ ·Ε͍ͯΔϞδϡʔϧʹPKPQNͱ͍͏ͷ͕͋Γ· ͢ w

    ϞδϡʔϧεΠονͷA.Aͱηοτʹ͢Δͱɺ .PKPʹͳΓ·͢ɻ
  89. ʮѨ෦׮ͷϗʔϜϖʔδʯ͔ ΒཁૉΛऔಘ

  90. ʮѨ෦׮ͷϗʔϜϖʔδʯ͔ ΒཁૉΛऔಘ # Ѩ෦׮͞ΜͷϗʔϜϖʔδ͔ΒtitleλάΛऔಘ $ perl -Mojo -E \ 'say

    g("http://abehiroshi.la.coocan.jp/")->dom->at("title")' | nkf -w <title>Ѩ෦׮ͷϗʔϜϖʔδ</title> # Ѩ෦׮͞ΜͷϗʔϜϖʔδ͔Β஀ੜ೔Λऔಘ $ perl -Mojo -E \ 'say g("http://abehiroshi.la.coocan.jp/top.htm")->dom("td")->[4]->text' | nkf -w ੜ೥݄೔ 1964೥6݄22೔
  91. .BD#PPLͷ੔උ඼৘ใΛ νΣοΫ͍ͨ͠

  92. .BD#PPLͷ੔උ඼৘ใΛνΣοΫ͍ͨ͠ # MacBook੔උࡁ੡඼ͷҰཡΛऔಘ $ perl -MData::Dumper -Mojo -C -E \

    '$url = "https://www.apple.com/jp/shop/browse/home/specialdeals/mac/macbook"; \ map { push @$hash, $_->text } g("$url")->dom->find("span[itemprop=\"price\"]")->each; \ g("$url")->dom->find(".specs")->each( sub { my ($e, $num) = @_; \ say join(", ", $hash->[$num-1], $e->text) }) ' ˇ120,800 (੫ผ), 2017೥6݄ൃച 12Πϯνʢର֯ʣLEDόοΫϥΠτσΟεϓϨΠɺ2,304 x 1,440ϐΫηϧղ૾౓ɺ226ppi 8GB 1,866 ΦϯϘʔυϝϞϦ 256GB PCIeϕʔεΦϯϘʔυϑϥογϡετϨʔδ 480p FaceTimeΧϝϥ Intel HD Graphics 615 ˇ120,800 (੫ผ), 2017೥6݄ൃച 12Πϯνʢର֯ʣLEDόοΫϥΠτσΟεϓϨΠɺ2,304 x 1,440ϐΫηϧղ૾౓ɺ226ppi 8GB 1,866 ΦϯϘʔυϝϞϦ 256GB PCIeϕʔεΦϯϘʔυϑϥογϡετϨʔδ 480p FaceTimeΧϝϥ Intel HD Graphics 615
  93. PKPQN w ଞʹ΋PKPQNʹ͸ૉఢͳϫϯϥΠφʔίϚϯυ͕ͨͪ͋Γ·͢ w IUUQNPKPMJDJPVTPSHQFSMEPDPKP w IUUQTNPKPMJDJPVTJPCMPHEBZPOFMJOFSTGPSGVO BOEQSPpU w KTPOͰग़ྗͨ͠ΓɺϫϯϥΠφʔͰ8&#ΞϓϦΛ্ཱͪ͛ͨΓɺϕϯνϚʔ

    ΫͳͲ΋ग़དྷΔΑ͏Ͱ͢
  94. ͪΐͬͱͨ͠όάใࠂ࣌ʹ

  95. ͪΐͬͱͨ͠όάใࠂ࣌ʹ w 63*ϞδϡʔϧΛ࢖͍ͬͯΔՕॴͰɺ༧ظͤ͵Τϥʔ ͕ग़ͨ৔߹ w ϫϯϥΠφʔͳΒɺͨͬͨߦ͚ͩͰϙΠϯτΛઆ໌Մೳ $ perl -MURI -E

    'say URI->new("http://yapcjapan.org")->host ' yapcjapan.org # ϢʔβଆͰೖΕͨURLͷεΩʔϜ͕ෆ׬શͳͨΊɺdieͯ͠͠·͏έʔε͕ൃੜ $ perl -MURI -E 'say URI->new("ttp://yapcjapan.org")->host ' Can't locate object method "host" via package "URI::_foreign" at -e line 1. # ͜͏͢Ε͹OK $ perl -MURI -E 'my $uri = URI->new("ttp://yapcjapan.org/"); \ $uri->scheme('http') unless $uri->scheme =~ /^https?/; say $uri->host ' yapcjapan.org
  96. ࣄྫฤ͓ΘΓ

  97. ϫϯϥΠφʔΛ࢖͍΍͘͢͢ ΔͨΊͷUJQT

  98. ϫϯϥΠφʔΛ࢖͍΍͘͢͢ ΔͨΊͷUJQT w ώετϦ͸ๅͷࢁ w γΣϧͷIJTUPSZ͸ͱʹ͔͘େྔʹ࢒͓ͯ͠ ͘ w QFDPΛΠϯετʔϧͯ͠ɺ$USMSͷΠϯΫϦ ϝϯλϧαʔνΛߋʹศརʹͯ͠࢖͍·Θ͢

  99. ϫϯϥΠφʔΛ࢖͍΍͘͢͢ ΔͨΊͷUJQT w جຊ͸ώετϦΛ$USMSͰྑ͍͕ɺ·ͩ׳Εͯͳ͔ͬͨΓɺ·ͨ࢖͍ͦ͏Ͱ ͋Ε͹εχϖοτπʔϧʹొ࿥͓ͯ͘͠ w ࣗ෼͸Ҏલ͸4IFFUͱ͍͏εχϖοτπʔϧΛ࢖͍ͬͯ·ͨ͠ɻ w IUUQPTDBSEFMCFODPNTIFFU w

    ίϚϯυϥΠϯͷΈͰࡁΉͷͰ͔ͳΓศར w .BDͷํͰ͸ w ͱ͍͏ΫϦοϓϘʔυ֦ுεχϖοτొ࿥͕Ͱ͖ΔπʔϧΛ࢖ͬͨΓ͠ ͍ͯ·͢ɻ w IUUQXXXDMJQNFOVDPNKB
  100. ϫϯϥΠφʔΛ࢖͍΍͘͢͢ ΔͨΊͷUJQT w ʜ͔͠͠࠷ۙͰ͸ɺ6/*9ͷ఩ֶͷݪ఺ճؼతʹɺ εχϖοτ؅ཧʹ͸%SPQCPYͰ֤छςΩετϑΝ Πϧʹશ෦ಥͬࠐΉΑ͏ʹ͍ͯ͠·͢ɻ w ଟগݕࡧ͸஗ͯ͘΋ɺ͢΂ͯΛςΩετϑΝΠ ϧʹ͓͍ͯͯ͠ɺ͍ͭͰ΋HSFQSग़དྷΔͷ ͸΍ͬͺΓ҆৺

    w ݸਓͷײ૝Ͱ͢ʣ
  101. ϫϯϥΠφʔͷ஫ҙ఺

  102. ϫϯϥΠφʔͷ஫ҙ఺ w ϫϯϥΠφʔ͸͋͘·Ͱ΋ૣ͘࢓ࣄΛย෇͚Δ ͨΊͷ΋ͷͰ͋ͬͯɺ߃ٱతʹ࢖͏Α͏ͳ΋ͷ Ͱ͸ͳ͍ࣄ͕ଟ͍ɻ w ࠓޙ΋௕͘࢖͏ॏཁͳ࡞ۀͰ͋Ε͹ɺ͖ͪΜͱ εΫϦϓτΛ૊ΜͰɺHJU؅ཧ͢΂͖ɻ w ౰વͳ͕Β(6**%&ͷํ͕ޮ཰͕ྑ͍৔߹΋͋

    Γ·͢ɻྟػԠมʹ࢖͍෼͚·͠ΐ͏
  103. ·ͱΊ

  104. ·ͱΊ w ϫϯϥΠφʔͰָΛͯ͠࡞ۀΛૣ͘ऴΘΒͤΑ͏☺ w 6/*9ͷ఩ֶॏཁ w εϞʔϧŋΠζŋϏϡʔςΟϑϧ w ෺ࣄ͸γϯϓϧʹɺԿࣄʹ΋ૄ݁߹Λҙࣝ͠Α͏ w

    ಛʹ1FSMΛ஌͍ͬͯΔͱ$-*ܥͰͷ࡞ۀશൠʹ΋࢖ ͍ճ͠Ͱ͖͓ͯಘʂʂʂ
  105. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

  106. ͓ΘΓ