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
RE: AWK
Search
wtnabe
February 15, 2014
Programming
270
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RE: AWK
Introduction of Regular Expression and AWK on my own
wtnabe
February 15, 2014
More Decks by wtnabe
See All by wtnabe
Rubyでもモノリポしたい - 調査、おわわり編 -
wtnabe
0
62
Ruby de Railway Oriented Programming
wtnabe
0
110
Bindanのススメ
wtnabe
0
65
そのオブジェクト、何を保証してくれますか? - GuideRailのススメ -
wtnabe
0
78
Effective Jekyll
wtnabe
0
99
5 min Jekyll/Liquid Plugin cooking
wtnabe
0
68
Ruby de Wasm
wtnabe
0
94
Cloud Native Buildpacksって結局どうなの?
wtnabe
0
82
Decoupled System with Turbo Frame
wtnabe
1
180
Other Decks in Programming
See All in Programming
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
140
数百円から始めるRuby電子工作
tarosay
0
140
torikago - Ruby::Boxで照らすモジュラモノリスの実行境界
se4weed
1
340
Google Apps Script で Ruby を動かす
kawahara
0
130
Built Our Own Background Agent at LayerX
layerx
PRO
9
4.9k
yield再入門 #phpcon
o0h
PRO
0
960
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
370
仕様駆動開発の消費期限
watany
12
5.6k
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
580
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
290
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
460
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
510
Featured
See All Featured
Code Review Best Practice
trishagee
74
20k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
760
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Why Our Code Smells
bkeepers
PRO
340
58k
Become a Pro
speakerdeck
PRO
31
6.1k
Into the Great Unknown - MozCon
thekraken
41
2.7k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
240
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
350
Marketing to machines
jonoalderson
1
5.6k
エンジニアに許された特別な時間の終わり
watany
108
250k
Transcript
RE: AWK @wtnabe Kanazawa.rb meetup #18 2014-02-15 (Sat) at IT
Plaza MUSASHI
Abstract
Regular Expression Basics AWK Basics
Regular Expression Basics
Difficulties of RE Many different implementations Complex Character Sequences
Rough Classification POSIX ( Basic / Extended ) PCRE (Perl
Compatible Regular Expression) PHP, Apache, GNU Grep, ... GNU ( Basic / Extended ) and more
Ignore Minor tool's original expressions What does grep in your
tools mean ?
Basic Syntax Literal Character Meta Character / Escape Sequence Character
List / Character Class Grouping and Back reference
Elementary Operators . * + ? | () grouping and
back reference
Elementary Operators ^ $ ( \A \z ) \r \n
\s \xXX escape sequence [] [^] character list
RE Literal and Language Syntax Such as escape sequence CONFLICT
with parent language Some Languages have RE Literal AWK, Perl, Ruby, JavaScript, ...
Examples /^[0-9]+(-[0-9]+)+$/ /\s[Kk]anazawa\.rb\s/ %r{\bhttps?://.*\b}
Keep away Too Match /[0-9-]+/ Complex one-shot match q{[^"'<>]*(? :"[^"]*"[^"'<>]*|'[^']*'[^"'<>]*)*(?
:>|(?=<)|$(?!\n))}; #'}}}} cf. Perlメモ
AWK
Name from famous Human Names Aho Weinberger Kernighan
Filter-oriented Programming Language $ awk 'script' srcfile $ cat srcfile
| awk 'script' > destfile $ awk -f script srcfile
Basic Syntax C-like / Shell-like ( semicolon less ) Patterns
and Actions No need to write about stdin and split
Patterns and Actions pattern { action } pattern { action
}
BEGIN and END rule BEGIN { ... } END {
... }
Example Count a number of gems depending on from Gemfile.lock
Gemfile.lock GEM remote: https://rubygems.org/ specs: blankslate (2.1.2.4) ... PLATFORMS ruby
DEPENDENCIES ...
BEGIN { counting = 0 } /^$/ { counting =
0 } counting == 1 && !/:/ { print $1 } /^GEM$/ { counting = 1 }
$ awk -f script.awk Gemfile.lock | \ sort | uniq
| wc -l
Same as NF == 2 && $2 ~ /\(.*\)/ {print
$1}
Notes http://www.regular-expressions.info/ 正規表現メモ The GNU Awk User's Guide The GAWK
Manual - Table of Contents