Upgrade to Pro — share decks privately, control downloads, hide ads and more …

awk basics

awk basics

awkの使い方を紹介します。

競プロもくもくわいわい会 2023/05/22

yammerjp

May 22, 2023
Tweet

More Decks by yammerjp

Other Decks in Programming

Transcript

  1. தࢁܚ༞ ΍Μ·ʔ

    BXLCBTJDT
    ڝϓϩ΋͘΋͘Θ͍Θ͍ձ

    View full-size slide

  2. தࢁܚ༞
    w ৬ۀ8FCΞϓϦέʔγϣϯ
    ΤϯδχΞ ʙ

    w झຯEPU
    fi
    MFTͷ؅ཧ
    w झຯBXLΛॻ͘͜ͱ
    w 5XJUUFS(JU)VCZBNNFSKQ
    ΍Μ·ʔ

    View full-size slide

  3. BXL͸
    ςΩετॲཧʹಛԽͨ͠ϓϩάϥϛϯάݴޠ

    View full-size slide

  4. BXL͸
    ඪ४ೖྗΛѻ͏ͷ͕ಘҙ

    View full-size slide

  5. BXL͸
    ڝٕϓϩάϥϛϯά΋΍Γ΍͍͢


    View full-size slide

  6. ࣮༻తͳBXLͷ࢖͍ํ

    View full-size slide

  7. ྫBQBDIFͷΞΫηεϩά͔Β*1ΞυϨεΛൈ͖ग़͢

    ʜۭന۠੾Γͷ൪໨ͷϑΟʔϧυ

    View full-size slide

  8. ྫBQBDIFͷΞΫηεϩά͔Β*1ΞυϨεΛൈ͖ग़͢

    ʜۭന۠੾Γͷ൪໨ͷϑΟʔϧυ
    cat access.log | awk ‘{ print $1 }’ | head -3
    ʜۭന۠੾Γͷ൪໨ͷϑΟʔϧυ

    View full-size slide

  9. BXLͷϢʔεέʔεͷ൒෼Ҏ্͸͜Ε

    ӕͩͱࢥͬͨ͋ͳͨɺ4MBDLΛʮBXLʯͰݕࡧͯ͠ΈΔͱ͍͍Ͱ͢

    View full-size slide

  10. BXLͷॻ͖ํ

    View full-size slide


  11. جຊจ๏
    ɹɹɹɹɹɹɹɹɹύλʔϯ\ΞΫγϣϯ^
    ɾύλʔϯ͕Ұக͢ΔߦʹɺΞΫγϣϯΛ࣮ߦ
    ɾύλʔϯΛলུ͢Δʜਅ શߦʹΞΫγϣϯΛద༻

    ɾΞΫγϣϯΛলུ͢Δʜ\QSJOU^ ߦશମΛग़ྗ

    View full-size slide


  12. ಛघͳม਺
    ඪ४ೖྗͷߦશମ
    ʜۭന۠੾ΓͷO൪໨ͷϑΟʔϧυ
    /'ϑΟʔϧυ਺
    /3ݱࡏͷߦ൪߸

    View full-size slide


  13. <4FQ>(&5XQ DBU)551ʜུ
    <4FQ>(&5TDSJQUJOHKBWBIUNMʜུ
    <4FQ>(&5XQ TSBTQCFSSZQʜུ









    /'
    /3
    ಛघͳม਺

    View full-size slide


  14. <4FQ>(&5XQ DBU)551ʜུ
    <4FQ>(&5TDSJQUJOHKBWBIUNMʜུ
    <4FQ>(&5XQ TSBTQCFSSZQʜུ









    /'
    /3
    ಛघͳม਺

    View full-size slide


  15. <4FQ>(&5XQ DBU)551ʜུ
    <4FQ>(&5TDSJQUJOHKBWBIUNMʜུ
    <4FQ>(&5XQ TSBTQCFSSZQʜུ








    /'
    /3
    ಛघͳม਺

    View full-size slide

  16. ྫߦ໨ͷ*1ΞυϨεΛग़ྗ


    NR==33 { print $1 }

    View full-size slide

  17. ྫ֤ߦͷۮ਺ྻͷϑΟʔϧυΛग़ྗ


    {


    for(i=1; i<=NF; i++) {


    if(i%2==0) {


    if(i!=1) {


    printf(“ “)


    }


    printf(“%s”, $i)


    }


    }


    printf(“\n”)


    }
    IUUQTHJTUHJUIVCDPNZBNNFSKQEECBBFGCEFDEB

    View full-size slide

  18. ྫ"#$


    $0=$(gsub(_,FS)/2)
    ɾʮʹ୅ೖ͢Δʯͱ͍͏ύλʔϯ㱺ਅ
    ɾਅͳͷͰɺΛग़ྗ
    ˠʮQSJOUʯͱॻ͘ͱ͜ΖΛɺʮʯͱॻ͍ͯจࣈ਺અ໿
    IUUQTHJTUHJUIVCDPNZBNNFSKQDEBCFCGEDG

    View full-size slide

  19. εϥΠυதͷBDDFTTMPH͸ɺॻ੶ʮϚελϦϯά-JOVYγΣϧεΫϦϓτʯͷαϯϓϧίʔυΛ࢖༻͍ͯ͠·͢
    IUUQTHJUIVCDPNPSFJMMZKBQBONBTUFSJOHMJOVYTIFMMTDSJQUJOHFKBCMPCNBJODIBDDFTTMPH

    View full-size slide

  20. BXLΛͨͷ͠΋͏

    View full-size slide