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
250
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でもモノリポしたい - 調査、おわわり編 -
wtnabe
0
21
Ruby de Railway Oriented Programming
wtnabe
0
47
Bindanのススメ
wtnabe
0
35
そのオブジェクト、何を保証してくれますか? - GuideRailのススメ -
wtnabe
0
47
Effective Jekyll
wtnabe
0
77
5 min Jekyll/Liquid Plugin cooking
wtnabe
0
41
Ruby de Wasm
wtnabe
0
71
Cloud Native Buildpacksって結局どうなの?
wtnabe
0
57
Decoupled System with Turbo Frame
wtnabe
1
140
Other Decks in Programming
See All in Programming
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
2
640
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
7
2.4k
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
0
110
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
150
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
39
26k
Deno Tunnel を使ってみた話
kamekyame
0
300
Go コードベースの構成と AI コンテキスト定義
andpad
0
150
GoLab2025 Recap
kuro_kurorrr
0
790
Denoのセキュリティに関する仕組みの紹介 (toranoana.deno #23)
uki00a
0
210
AI 駆動開発ライフサイクル(AI-DLC):ソフトウェアエンジニアリングの再構築 / AI-DLC Introduction
kanamasa
11
4.8k
CSC307 Lecture 01
javiergs
PRO
0
650
PostgreSQLで手軽にDuckDBを使う!DuckDB&pg_duckdb入門/osc25hi-duckdb
takahashiikki
0
230
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
73
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
97
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
2
76
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
42
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
1
210
How to Talk to Developers About Accessibility
jct
1
94
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
590
Leo the Paperboy
mayatellez
0
1.3k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
41
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
0
50
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