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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
More Decks by Satoru Takeuchi
See All by Satoru Takeuchi
119-多機能ファイルシステムBtrfs_のコピー.pdf
sat
PRO
1
66
Linuxカーネルの インタフェースは変わりうる?
sat
PRO
1
92
あなたの知らないバージョン命名規則
sat
PRO
3
890
Rook: Intro and Deep Dive with Ceph
sat
PRO
1
64
Machine Check Exception
sat
PRO
2
63
バイナリダンプの模様を読む
sat
PRO
0
88
cpコマンドはディスク上でデータを コピーしないことがある
sat
PRO
3
87
114-ファイルのshallow_copy.pdf
sat
PRO
2
57
113-Btrfsのスナップショット.pdf
sat
PRO
0
40
Other Decks in Technology
See All in Technology
なぜSRE・セキュリティは評価されないのか?守りの組織を事業成長エンジンに変えた実践
cscengineer
PRO
3
2.4k
Podは生きているのにGoだけが落ちる:GOGCとGOMEMLIMITで追うInvisible OOM Killの謎
tkc66buzz
1
240
Webとヘルスデータ
yukukotani
1
200
AI-DLCって実際どう? 〜聞きたいこと全部聞いてみる〜
news_it_enj
0
250
AIで実装は速くなった。なのにプロダクトは速くならない。職能の壁を越えて価値のフローを設計する
nwiizo
7
7.6k
omasushiというライブラリを作った
polidog
PRO
0
170
2026-09-09 【sigma_ucj#1】Sigma を IaC 管理したい! / IaC for Sigma
civitaspo
0
100
コスト最適化の「めんどくさい」を AWS FinOps Agent でチョット楽にする
classmethod_kaz
0
290
アプリをもっと"iOSアプリっぽく"する小さな工夫 / Small Touches That Make Your App Feel More Like an iOS App
matsuji
1
170
V8コントリビュート超入門
riyaamemiya
0
160
作品が生態系になった ─ Mini Tokyo 3D から世界へ
nagix
0
150
Sigmaで作る業務アプリ
kazushiro_honma
0
100
Featured
See All Featured
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
230
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
580
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.3k
GitHub's CSS Performance
jonrohan
1033
470k
How to Think Like a Performance Engineer
csswizardry
28
2.8k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
Balancing Empowerment & Direction
lara
6
1.3k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Six Lessons from altMBA
skipperchong
29
4.5k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
510
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
Transcript
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