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
260
0
Share
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
45
Ruby de Railway Oriented Programming
wtnabe
0
93
Bindanのススメ
wtnabe
0
58
そのオブジェクト、何を保証してくれますか? - GuideRailのススメ -
wtnabe
0
73
Effective Jekyll
wtnabe
0
95
5 min Jekyll/Liquid Plugin cooking
wtnabe
0
58
Ruby de Wasm
wtnabe
0
90
Cloud Native Buildpacksって結局どうなの?
wtnabe
0
74
Decoupled System with Turbo Frame
wtnabe
1
170
Other Decks in Programming
See All in Programming
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
270
Hive Metastoreを通して学ぶIceberg REST Catalog ― 仕様から実装まで
okumin
0
280
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
240
関係性から理解する"同一性"の型用語たち
pvcresin
2
540
inferと仲良くなる10分間
ryokatsuse
1
260
CLIであることを活かしたGitHub Copilot CLI活用術 / GitHub Copilot CLI Pro Tips & Tricks
nao_mk2
1
1.1k
TypeSpec で繋ぐ複数プロダクトの型安全
maroon8021
1
250
AI 時代のソフトウェア設計の学び方
masuda220
PRO
27
9.4k
GitHub Copilot CLIのいいところ
htkym
2
1.1k
プロパティの順序で型推論が壊れる!? TypeScript6.0の修正からContext-Sensitivityの仕組みを追う
bicstone
2
1.1k
誰も頼んでない機能を出荷した話
zekutax
0
140
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
7
2.3k
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
450
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
540
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
The Pragmatic Product Professional
lauravandoore
37
7.3k
The Curious Case for Waylosing
cassininazir
1
360
Code Reviewing Like a Champion
maltzj
528
40k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Game over? The fight for quality and originality in the time of robots
wayneb77
1
180
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
290
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
460
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
130
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