Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
知って得するかもしれないテキスト処理コマンドの話 / A story about text ...
Search
Ryo Shibayama
February 27, 2015
Technology
45
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
知って得するかもしれないテキスト処理コマンドの話 / A story about text processing commands that you might get to know
Ryo Shibayama
February 27, 2015
More Decks by Ryo Shibayama
See All by Ryo Shibayama
技術広報の集い #3 Lightning Talk - LayerX
serima
0
450
採用は全員で | Chuo TECH #1
serima
4
1.5k
高専 5 年時に 7 泊 8 日の合宿型ビジコンに参加したら人生が変わった
serima
0
460
カジュアル面談を通して “自社”のことを知る
serima
0
290
倒れても進捗 / Progress even if I fall
serima
1
880
CircleCI 導入への入門 / Introduction to CircleCI
serima
0
140
GameWithを支えるインフラ基盤 - スケールイン・アウト戦略編 / GameWith infrastructure - Scale in and out strategy
serima
0
99
エンジニア採用と PHP / Engineer Recruitment and PHP
serima
0
120
できることから始める OSS Contribution / Start OSS Contribution With What You Know
serima
1
280
Other Decks in Technology
See All in Technology
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
15
110k
Aurora MySQL 8.4リリース! Rubyistが備えること / what-rubyist-should-prepare-for-aurora-mysql-8-4
fkmy
0
1.1k
Multicaで30個のミニプロジェクトをAIエージェント運用して見えてきたこと
eiei114
1
650
穢れた技術選定について
watany
19
6.2k
AWS環境のセキュリティ不安を解消した企業事例 ~よくある課題と対策を一挙公開~
asanoharuki
0
160
10年目を迎えた「ABEMA」がどのように AI 活用を推進して、AI 駆動開発にシフトしているのか / How ABEMA, entering its 10th year, is promoting the use of AI and shifting toward AI-driven development
miyukki
0
380
AI時代のPlaywright活用(システムテストを自動化する ー 実行エンジンにPla ywrightを選んだ理由)
ynisqa1988
2
1k
AI、CDK と協働する Full TypeScript アプリケーション開発 / Full TypeScript Application with AI and CDK
geekplus_tech
2
500
「休む」重要さ
smt7174
6
1.7k
StepFunctionsとGraphRAGを活用した暗黙知活用のためのRAG基盤
yakumo
0
160
現場との対話から始める “作る前に問い直す”業務改善
mochico50
2
280
GoでCコンパイラを作った話
repunit
0
160
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Writing Fast Ruby
sferik
630
63k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
610
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.3k
Optimizing for Happiness
mojombo
378
71k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
910
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
390
Visualization
eitanlees
152
17k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Transcript
知って得するかもしれない テキスト処理理コマンドのお話 @serima
⾃自⼰己紹介 | PHP歴 今年年で 8 年年⽬目 初めての PHP 勉強会への参加
今後も頑張りたい
ビッグデータと僕 ソーシャルゲームの運⽤用 データ命 アクセスログ、課⾦金金ログ、戦闘ロ グ、カード取得ログ…
データのダンプ mysqldump scp
TreasureData あらゆるログを TreasureData に集 約 これで取り出しやすくはなった
ディレクターさん 「せりまさん、こんなデータ取って ください」 「おk」
巨⼤大なデータ いざ取り出してみると、数⼗十万〜~数 百万⾏行行になることはザラ この規模のデータを Excel で開くと 死亡 なので、ある程度度サマリする必要が
でてきます
サマリするためのスクリプト データ規模が⼤大きくなってくると PHP つかって書くと超遅い
それ… UNIX コマンドでできるよ
よく使うコマンド cat, sort, uniq, wc, grep, awk, diff, cut,
sed
join ふたつのファイルの共通 key で連結 ふたつのファイルは結合するフィー ルドで sort しておく必要がある
join の使⽤用例例 a.txt には ユーザ ID, 課⾦金金額, 戦闘⼒力力 の順で⼊入ってる
b.txt には ユーザ ID, ユーザ名 の順で⼊入ってる join -‐‑‒a1 -‐‑‒eʼ’-‐‑‒ʼ’ -‐‑‒oʼ’0 1.2 1.3 2.2ʼ’ <(sort a.txt) <(sort b.txt)
プロセス置換 | 知ってる? <(sort a.txt) bash や zsh の機能
sort 済みのテンポラリファイルを作 る必要がなくなる
プロセス置換 | 知らない これを知るまで cat a.txt | sort >
a_̲sorted.txt 無駄なファイル量量産してた
集合演算っぽいこと A に含まれるが、B に含まれない ID を出したい 1 2
3 1 3 2 A B ほしい結果
差集合 diff と awk でできるよ diff <(sort A) <(sort B)
| awk ʻ‘/^</{print $2}ʼ’
他の集合演算 和集合 A∪B cat A B | sort |
uniq 積集合 A∩B cat A B | sort | uniq -‐‑‒d join A B
join コマンド join コマンドはとても便便利利だけど、 ふたつの引数しかとることができな い
tsv や csv に query 投げたい あるんです q -‐‑‒
Text as Data https://github.com/harelba/q q って!ググラビリティ低すぎ
試しに使ってみる % seq 1 1000 | q "select avg(c1),sum(c1) from
-‐‑‒" 500.5 500500 c1というのが、カラムの1番⽬目という意味なので、 avg(c1)で、1〜~1000の総和の平均 sum(c1)で、1〜~1000の総和 がちゃんと出てますね
GROUP BY も使える % cat test.txt Mike
10 John 1 Bob 8 Mary 19 Bob 15 Bob 20 Mike 2 % q "select c1, count(*), sum(c2) from test.txt group by c1" Bob 3 43 John 1 1 Mary 1 19 Mike 2 12
JOIN も使える % cat test1.txt a1234 aa1
b1234 aa2 c1234 aa3 d1234 aa3 ! % cat test2.txt 1 a1234 bb1 2 a1234 bb2 3 b1234 cc1 4 c1234 dd3 5 e1234 NULL ! % q "select * from test1.txt as a left join test2.txt as b on a.c1 = b.c2" a1234 aa1 1 a1234 bb1 a1234 aa1 2 a1234 bb2 b1234 aa2 3 b1234 cc1 c1234 aa3 4 c1234 dd3 d1234 aa3
ご清聴ありがとうございました ブログにこの事書いてるのでご興味 あればどうぞ http://serima.co/blog