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
210
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 de Wasm
wtnabe
0
21
Cloud Native Buildpacksって結局どうなの?
wtnabe
0
17
Decoupled System with Turbo Frame
wtnabe
1
70
join-kanazawarb-or-7years-passed-since-it-was-borned
wtnabe
0
730
let-me-edit-with-editor
wtnabe
0
290
google-photos-and-storage-and-rclone
wtnabe
0
390
one case of how to begin vuejs
wtnabe
2
420
Kanazawa.rb meetup #56 Coderetreat Intro
wtnabe
0
410
lightweight authenticity of microservices
wtnabe
0
420
Other Decks in Programming
See All in Programming
CSC305 Lecture 25
javiergs
PRO
0
130
Develop iOS apps with Neovim / vimconf_2024
uhooi
1
340
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
1
730
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
3.8k
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
130
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
150
Djangoの開発環境で工夫したこと - pre-commit / DevContainer
hiroki_yod
1
700
useSyncExternalStoreを使いまくる
ssssota
4
870
eBPF Deep Dive: Architecture and Safety Mechanisms
takehaya
12
1.3k
社内活動の取り組み紹介 ~ スリーシェイクでこんな取り組みしてます ~
bells17
0
400
Vapor Revolution
kazupon
2
2.6k
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
100
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Navigating Team Friction
lara
183
15k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Docker and Python
trallard
41
3.1k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
1
150
Making the Leap to Tech Lead
cromwellryan
133
9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
What's in a price? How to price your products and services
michaelherold
243
12k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
160
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