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
0
240
RE: AWK
Introduction of Regular Expression and AWK on my own
wtnabe
February 15, 2014
Tweet
Share
More Decks by wtnabe
See All by wtnabe
Ruby de Railway Oriented Programming
wtnabe
0
33
Bindanのススメ
wtnabe
0
26
そのオブジェクト、何を保証してくれますか? - GuideRailのススメ -
wtnabe
0
38
Effective Jekyll
wtnabe
0
67
5 min Jekyll/Liquid Plugin cooking
wtnabe
0
34
Ruby de Wasm
wtnabe
0
61
Cloud Native Buildpacksって結局どうなの?
wtnabe
0
50
Decoupled System with Turbo Frame
wtnabe
1
130
join-kanazawarb-or-7years-passed-since-it-was-borned
wtnabe
0
800
Other Decks in Programming
See All in Programming
CSC509 Lecture 08
javiergs
PRO
0
270
data-viz-talk-cz-2025
lcolladotor
0
100
開発組織の戦略的な役割と 設計スキル向上の効果
masuda220
PRO
10
2k
SidekiqでAIに商品説明を生成させてみた
akinko_0915
0
110
スマホから Youtube Shortsを見られないようにする
lemolatoon
27
34k
CSC305 Lecture 12
javiergs
PRO
0
250
Reactive Thinking with Signals and the Resource API
manfredsteyer
PRO
0
120
Blazing Fast UI Development with Compose Hot Reload (droidcon London 2025)
zsmb
0
430
ドメイン駆動設計のエッセンス
masuda220
PRO
15
6.9k
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
380
Claude Agent SDK を使ってみよう
hyshu
0
1.4k
モテるデスク環境
mozumasu
3
1.4k
Featured
See All Featured
Facilitating Awesome Meetings
lara
57
6.6k
The Pragmatic Product Professional
lauravandoore
36
7k
Embracing the Ebb and Flow
colly
88
4.9k
Code Review Best Practice
trishagee
72
19k
KATA
mclloyd
PRO
32
15k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
116
20k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
22k
Building a Modern Day E-commerce SEO Strategy
aleyda
44
7.9k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Practical Orchestrator
shlominoach
190
11k
Building an army of robots
kneath
306
46k
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