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
210
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 Wasm
wtnabe
0
14
Cloud Native Buildpacksって結局どうなの?
wtnabe
0
14
Decoupled System with Turbo Frame
wtnabe
1
63
join-kanazawarb-or-7years-passed-since-it-was-borned
wtnabe
0
720
let-me-edit-with-editor
wtnabe
0
280
google-photos-and-storage-and-rclone
wtnabe
0
370
one case of how to begin vuejs
wtnabe
2
410
Kanazawa.rb meetup #56 Coderetreat Intro
wtnabe
0
400
lightweight authenticity of microservices
wtnabe
0
420
Other Decks in Programming
See All in Programming
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
160
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
1.5k
役立つログに取り組もう
irof
28
9.3k
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
780
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
540
C++でシェーダを書く
fadis
6
3.9k
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
270
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
220
デプロイを任されたので、教わった通りにデプロイしたら障害になった件 ~俺のやらかしを越えてゆけ~
techouse
53
34k
約9000個の自動テストの 時間を50分->10分に短縮 Flakyテストを1%以下に抑えた話
hatsu38
24
12k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
440
Featured
See All Featured
Become a Pro
speakerdeck
PRO
25
5k
Measuring & Analyzing Core Web Vitals
bluesmoon
2
75
Happy Clients
brianwarren
97
6.7k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Six Lessons from altMBA
skipperchong
26
3.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
404
65k
KATA
mclloyd
29
14k
A Tale of Four Properties
chriscoyier
156
23k
4 Signs Your Business is Dying
shpigford
180
21k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
How to Ace a Technical Interview
jacobian
276
23k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
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