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
200
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
49
join-kanazawarb-or-7years-passed-since-it-was-borned
wtnabe
0
680
let-me-edit-with-editor
wtnabe
0
250
google-photos-and-storage-and-rclone
wtnabe
0
330
one case of how to begin vuejs
wtnabe
2
380
Kanazawa.rb meetup #56 Coderetreat Intro
wtnabe
0
360
lightweight authenticity of microservices
wtnabe
0
380
Automate WordPress deployment with WordMove
wtnabe
1
420
CircleCI Hands-on for Beginners
wtnabe
0
390
Other Decks in Programming
See All in Programming
Microservices rules (July 2024) : what good looks like
cer
PRO
0
1.6k
Rubyのパフォーマンスプロファイリングの改善 / Enhancing performance profiling for Ruby
osyoyu
1
410
Advanced App Shrinking Techniques
cbeyls
2
150
Introduction to GitOps
hwchiu
0
110
社内 LT 会を発足し、アウトプット文化を醸成させるために考えたこと・やったこと / Starting internal LT meetings and fostering an output culture
mackey0225
3
120
CSC307 Lecture 05
javiergs
PRO
0
210
Temporalを取り巻く仕様を整理する
sajikix
0
110
小さな開発会社を作った理由
polidog
0
1.9k
英語
s_shimotori
1
220
生成AIをkintoneに連携してみた
hideg
0
230
今こそ始める、CDKコンストラクトライブラリ開発 ― 入門から実践まで
tmokmss
1
930
Async Await: Mastering Python's Time-Bending Tricks - EuroPython2024
yanbo
1
290
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
Making Projects Easy
brettharned
111
5.7k
No one is an island. Learnings from fostering a developers community.
thoeni
17
2.8k
Large-scale JavaScript Application Architecture
addyosmani
506
110k
Leading Effective Engineering Teams 2024
addyosmani
3
300
GraphQLの誤解/rethinking-graphql
sonatard
59
9.6k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
16
1.6k
It's Worth the Effort
3n
181
27k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
248
20k
Web development in the modern age
philhawksworth
203
10k
KATA
mclloyd
20
13k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.3k
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