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
KawaiiLT 登壇資料 キャリアとモチベーション
hiiragi
0
120
タイムゾーンの奥地は思ったよりも闇深いかもしれない
suguruooki
1
680
Youtube Lofier - Chrome拡張開発
ninikoko
0
2.4k
MCP調べてみました! / Exploring MCP
uhzz
2
2.3k
Lambda(Python)の リファクタリングが好きなんです
komakichi
3
200
Fiber Scheduler vs. General-Purpose Parallel Client
hayaokimura
1
100
Cursor/Devin全社導入の理想と現実
saitoryc
8
2.3k
Qiita Bash
mercury_dev0517
2
200
これだけは知っておきたいクラス設計の基礎知識 version 2
masuda220
PRO
24
6.4k
監視 やばい
syossan27
10
9.2k
SwiftUI API Design Lessons
niw
1
290
エンジニアが挑む、限界までの越境
nealle
1
220
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
52
7.5k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
104
19k
Automating Front-end Workflow
addyosmani
1369
200k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
Gamification - CAS2011
davidbonilla
81
5.2k
What's in a price? How to price your products and services
michaelherold
245
12k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
9
760
Speed Design
sergeychernyshev
29
900
Unsuck your backbone
ammeep
670
57k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.8k
GraphQLの誤解/rethinking-graphql
sonatard
71
10k
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