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
280
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
新しいフロントプロセスとドキュメントフォーマットを考えてみた
wtnabe
0
23
Rubyでもモノリポしたい - 調査、おさわり編 -
wtnabe
0
65
Ruby de Railway Oriented Programming
wtnabe
0
110
Bindanのススメ
wtnabe
0
68
そのオブジェクト、何を保証してくれますか? - GuideRailのススメ -
wtnabe
0
78
Effective Jekyll
wtnabe
0
100
5 min Jekyll/Liquid Plugin cooking
wtnabe
0
69
Ruby de Wasm
wtnabe
0
94
Cloud Native Buildpacksって結局どうなの?
wtnabe
0
84
Other Decks in Programming
See All in Programming
楽しそうなつよつよエンジニアと目が死んでる僕/A brilliant engineer having a blast, and dead-eyed me.
3l4l5
2
230
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
140
VibeCodingからAgenticWorkflowへ
starfish719
0
740
ソフトウェアラスタライザ
fadis
1
290
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
350
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
240
Flow は今どうなっているか
mizdra
PRO
0
670
AIを紡ぐPMのお話
swdtkuy
0
120
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
250
Dockerfile CMD for Node.js
grazie1999
0
110
今さら聞けない .NET CLI
htkym
0
210
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
5
500
Featured
See All Featured
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
380
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
66
57k
Music & Morning Musume
bryan
47
7.3k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
390
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Facilitating Awesome Meetings
lara
57
7.1k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Technical Leadership for Architectural Decision Making
baasie
3
520
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
790
Odyssey Design
rkendrick25
PRO
2
770
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