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
230
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
Effective Jekyll
wtnabe
0
31
5 min Jekyll/Liquid Plugin cooking
wtnabe
0
16
Ruby de Wasm
wtnabe
0
39
Cloud Native Buildpacksって結局どうなの?
wtnabe
0
31
Decoupled System with Turbo Frame
wtnabe
1
110
join-kanazawarb-or-7years-passed-since-it-was-borned
wtnabe
0
760
let-me-edit-with-editor
wtnabe
0
320
google-photos-and-storage-and-rclone
wtnabe
0
430
one case of how to begin vuejs
wtnabe
2
450
Other Decks in Programming
See All in Programming
「”誤った使い方をすることが困難”な設計」で良いコードの基礎を固めよう / phpcon-odawara-2025
taniguhey
0
160
趣味全開のAITuber開発
kokushin
0
200
Module Boundaries and Architecture with Forensic Analysis @NxSummit Amsterdam 2025
manfredsteyer
PRO
0
100
PHP で学ぶ OAuth 入門
azuki
1
210
Chrome Extension Techniques from Hell
moznion
1
160
Enterprise Web App. Development (1): Build Tool Training Ver. 5
knakagawa
1
120
スモールスタートで始めるためのLambda×モノリス(Lambdalith)
akihisaikeda
2
290
Contribute to Comunities | React Tokyo Meetup #4 LT
sasagar
0
500
Building Scalable Mobile Projects: Fast Builds, High Reusability and Clear Ownership
cyrilmottier
2
290
Kamal 2 – Get Out of the Cloud
aleksandrov
1
190
Building a macOS screen saver with Kotlin (Android Makers 2025)
zsmb
1
150
Youtube Lofier - Chrome拡張開発
ninikoko
0
2.4k
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
2.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Building a Modern Day E-commerce SEO Strategy
aleyda
40
7.2k
GraphQLとの向き合い方2022年版
quramy
46
14k
What's in a price? How to price your products and services
michaelherold
245
12k
Into the Great Unknown - MozCon
thekraken
37
1.7k
RailsConf 2023
tenderlove
30
1.1k
Docker and Python
trallard
44
3.3k
Navigating Team Friction
lara
184
15k
How STYLIGHT went responsive
nonsquared
99
5.5k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.4k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
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