Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
AWKへの愛を語る
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Satoru Takeuchi
PRO
August 24, 2024
Technology
680
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AWKへの愛を語る
kanazawa.rb #144のLT資料です
https://meetup.kzrb.org/144/
Satoru Takeuchi
PRO
August 24, 2024
Transcript
16 slides
AWKへの愛を語る Aug. 24th, 2024 kanazawa.rb #144 Satoru Takeuchi X: satoru_takeuchi
1
はなすこと • プログラミング言語AWKへの私からの愛のメッセージを語る 2
はなすこと • プログラミング言語AWKへの私からの愛のメッセージを語る • アイスブレイク ◦ AWK知ってる人は挙手! 3
はなすこと • プログラミング言語AWKへの私からの愛のメッセージを語る • アイスブレイク ◦ AWK知ってる人は挙手! ◦ AWK使ったことある人は挙手! 4
AWKとは • 1977年にAT&Tベル研究所で生まれた ◦ もう強そうなニオイが漂っている • 手早くテキスト処理をするための言語 ◦ 基本は1行ごとにプログラムを適用して処理する ◦
詳しくは後述 5
サンプル入力 • 1行1レコード • フィールドはtabで区切っている • 第一フィールドがCPUベンダ、第二フィールドがプロセッサの名前 6 $ cat
input.txt amd ryzen intel pentium amd athlon transmeta crusoe intel core amd opteron
第1フィールドを出力 7 $ awk '{print $1}' input.txt amd intel amd
transmeta intel amd
第2フィールドを出力 8 $ awk '{print $2}' input.txt ryzen pentium athlon
crusoe core opteron
ベンダがIntelのプロセッサの数を出力 9 $ awk '$1=="intel"{sum++}END{print sum}' input.txt 2
それ、他の言語でもできるよ…? • 例: Rubyで第2フィールドを表示する場合 10 $ ruby -e 'ARGF.each do
|l| puts l.chomp().split("\t")[1] end' input.txt ryzen …
それ、他の言語でもできるよ…? • 例: Rubyで第2フィールドを表示する場合 • ちょっと長いかな…(個人の感想) ◦ AWK: 10文字 ◦
Ruby: 50文字 • 他の言語でも似たり寄ったり 11 $ ruby -e 'ARGF.each do |l| puts l.chomp().split("\t")[1] end' input.txt ryzen …
📝: RubyはAWKっぽく書ける構文もある • Rubyで第2フィールドを表示する場合 • オプションの説明 ◦ -n: 一行ごとに-eの後の引数を評価する ◦
-a: フィールドを自動的にいいかんじに分割して配列 $Fに入れる 12 $ ruby -nae 'puts $F[1]' input.txt ryzen pentium …
📝: RubyはAWKっぽく書ける構文もある • Rubyで第2フィールドを表示する場合 • オプションの説明 ◦ -n: 一行ごとに-eの後の引数を評価する ◦
-a: フィールドを自動的にいいかんじに分割して配列 $Fに入れる • プログラム(-eの引数)は10文字だがオプション含めると14文字 ◦ まだ脊髄で書けない (個人の感想) 13 $ ruby -nae 'puts $F[1]' input.txt ryzen pentium …
AWKの使いどころ • 1行1レコードのテキストを脊髄反射で処理したい場合 • 数行をひとまとめとしたレコードが繰り返されるテキスト処理もなんとか • それ以外は全部他の言語でいいと思う 14 name: foo
desc: bar name: hoge desc: huga
プログラミング言語AWK第二版に全てが書かれている • 言語作者達が書いた • 全機能を網羅 • 最新機能のUnicode,CSV対応もカバー • 作られた経緯、その後の発展についての記述も 15
まとめ • AWKというプログラミング言語がある • 古臭いけど便利 • ワンライナーを脊髄でプログラミングできる 16
More Decks by Satoru Takeuchi
See All by Satoru Takeuchi
Btrfsのsnapshotとランダム書き込み
sat
PRO
0
57
ファイルシステムのデフラグ
sat
PRO
1
62
コピーオンライト型ファイルシステムと ランダム書き込み
sat
PRO
2
140
119-多機能ファイルシステムBtrfs_のコピー.pdf
sat
PRO
1
92
Linuxカーネルの インタフェースは変わりうる?
sat
PRO
1
120
あなたの知らないバージョン命名規則
sat
PRO
3
940
Rook: Intro and Deep Dive with Ceph
sat
PRO
1
92
Machine Check Exception
sat
PRO
2
79
バイナリダンプの模様を読む
sat
PRO
0
130
Other Decks in Technology
See All in Technology
お風呂場をサーバルームにしよう
yusuke427
0
400
専門家に使ってもらうAIプロダクトをつくる - 病院の医事課向けDPCコーディング支援システムの設計と評価
hagino3000
4
1.1k
設計手法を「道具」として使いこなすために
a_suenami
7
1.8k
Metadata - Section 4 : MODS (Metadata Object Description Schema )
mohab1
0
140
認知の質も文化醸成も。数年取り組んで見えてきた技術広報のKPI設計 / Tech PR KPIs: Lessons on Awareness Quality and Culture After Several Years
bitkey
PRO
0
220
20261119_AgentCore
takuyay0ne
2
310
人の努力に頼らないセキュリティをエンジニアリングする在り方 / An approach to engineering security that does not rely on human effort
carta_engineering
0
250
現場に渡し、構造で守る AI エージェントを活用したセルフサーブのデータ基盤の運用
legalontechnologies
PRO
0
120
FPGAでアクティブセンシングがやりたくてカメラモジュールを自作した話
ryuz88
0
100
「個社」ではなく「業界」の課題を解く AI 対話開発 ー 価値を広げる設計と、価値を守るエンジニアリング ー
ivry_presentationmaterials
4
890
現地速報! Microsoft Ignite アップデートレポート
kasada
1
460
AIフレンドリーなGenerative UIをJSXで
uhyo
2
280
Featured
See All Featured
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
470
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
630
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.3k
Crafting Experiences
bethany
1
460
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1.1k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
390
Discover your Explorer Soul
emna__ayadi
2
1.3k
Navigating Team Friction
lara
192
16k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
410
Large-scale JavaScript Application Architecture
addyosmani
516
110k
sira's awesome portfolio website redesign presentation
elsirapls
0
530