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
190
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
Decoupled System with Turbo Frame
wtnabe
1
36
join-kanazawarb-or-7years-passed-since-it-was-borned
wtnabe
0
630
let-me-edit-with-editor
wtnabe
0
230
google-photos-and-storage-and-rclone
wtnabe
0
300
one case of how to begin vuejs
wtnabe
2
360
Kanazawa.rb meetup #56 Coderetreat Intro
wtnabe
0
330
lightweight authenticity of microservices
wtnabe
0
350
Automate WordPress deployment with WordMove
wtnabe
1
390
CircleCI Hands-on for Beginners
wtnabe
0
360
Other Decks in Programming
See All in Programming
Behind VS Code Extensions for JavaScript / TypeScript Linnting and Formatting
unvalley
5
900
AWS CDKコントリビュートTIPS / aws-cdk-contribution-tips
gotok365
2
100
Goのmultiple errorsについて (2024年4月版)
syumai
3
590
VS Code をプロダクトにどう取り込むか
onomax
1
360
スキーマ駆動開発による品質とスピードの両立 - 私達は何故、スキーマを書くのか
kentaroutakeda
0
170
SwiftUIで使いやすいToastの作り方 / How to build a Toast system which is easy to use in SwiftUI
lovee
3
130
Fragment Composition of GraphQL
quramy
3
550
見た目から始める生産性向上
ikumatadokoro
7
820
PostmanでAPIの動作確認が楽になった話
h455h1
0
170
Elm Form Validation
bkuhlmann
0
510
Git Rebase
bkuhlmann
11
1.6k
try! Swift Tokyo 2024のLT枠に採択されたプロポーザルを出すときに考えていたこと
ski
0
350
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
91
13k
Designing the Hi-DPI Web
ddemaree
276
33k
Agile that works and the tools we love
rasmusluckow
325
20k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
357
22k
GraphQLの誤解/rethinking-graphql
sonatard
50
9.2k
Stop Working from a Prison Cell
hatefulcrawdad
266
19k
Building an army of robots
kneath
300
41k
What’s in a name? Adding method to the madness
productmarketing
PRO
16
2.6k
Making the Leap to Tech Lead
cromwellryan
124
8.5k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
jQuery: Nuts, Bolts and Bling
dougneiner
59
7.1k
The Brand Is Dead. Long Live the Brand.
mthomps
49
28k
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