workshop on regular expressions (regex)
Sa+So 17.+18. Februar 2007 in Herford
=== Inhalt
die Sprache der Muster anhand von Beispielen erlernen
programme:
grep mutt sed vim
evtl auch awk perl
=== Dozent
Sven Guckes
workshop_regex (at) guckes.net
fon +49-179-3966141.
== Teilnehmer:
Sven Guckes
Frank Matthieß
Simon Pamiés
Ulrich Rieke
Jorge Santos
Gisa Stubenrauch
Peter Voigt
== Organisator:
Jorge Santos
jorge.santos (at) liberdade (dot) de
GnuPG: 1024D/B488DA1F
=== Ort
linuxlernen.org HeadQuarters
Moenchstrasse 5, 32052 Herford
=== Kosten
60 Euro pro Teilnehmer
40 Euro fuer Studenten/Soldaten
20 Euro fuer Schueler
=== Verpflegung:
Getraenke stehen zur freien Verfuegung,
gegen den leeren Magen zum Mittag gibt es eine Vielzahl
Multikulti-Fast- & Lowfooddealer in unmittelbarer Naehe.
=== Anmeldung
bis zum Mi 31.Januar per email an
Jorge Santos jorge.santos (at) liberdade (dot) de
Fahrplan
=== Vorbereitung
zwei wochen vorher:
Mailingliste "workshop" mit vorabinfos bedienen.
beispiele geben. hausaufgaben.
um fragen fuer den workshop bitten.
=== Zeitplan
Fr 2007-02-16 --
So 2007-02-18
.
Fr 16.Februar Anreise der Externen
Fr 17.Februar Installation von Isomatte+Schlafsack.
Aufbau des Netzwerk + erster Test.
Sa 18.Februar 11:00-13:00 erster Teil
13:00-13:30 Mittagspause + Mampf
13:30-18:00 zweiter Teil
Regulaere Ausdruecke
So 19.Februar 11:00-13:00 dritter Teil
13:00-13:30 Mittagspause + Mampf
13:30-18:00 vierter Teil: sed und awk
abends: planung weiterer workshops
open end? :)
Mo 20.Februar Abreise nach Berlin
=== Auftakt
Freitag abend: netz installieren.
wlan kabel, switch, verlaengerungskabel.
getraenke aufstellen.
monitor switch (nicht vorhanden)
Samstag: anwesenheit pruefen.
wer ist wann da? wer muss wann wieder weg?
pause einplanen!
=== Inhalt
einfache regulaere ausdruecke
character classes: alnum alpha blank cntrl digit graph lower print punct space upper xdigit
dot
greediness of .*
== grep:
switches bei grep:
grep -h : grep -i ...
grep -i : grep -i gnu # GNU? Gnu? gnu?
grep -l : ls -l `grep -l Herford *`
grep -n : grep bash /etc/passwd
grep --color=always foo files... | less -r
== less:
startup with a search: less +/foo file
show the search word within the results:
function cache { apt-cache search $1 | less -S +/$1 }
function show { apt-cache show $1 | less -S +/$1 }
function mal { grep -i $1 ~/.mutt/aliases | less +/$1 }
== sed:
einfaches suchen und ersetzen
s/foo/bar/
s/foo/bar/g global flag
delete matching lines:
/RE/d
delete from line containing
RE1 to line RE2 (inclusive):
/RE1/,/RE2/d
beispiel:
/^-- $/,$d
apply a command to
non-matching lines:
/RE/!command
== vim:
delete whitespace at end of line:
:%s/\s\+$//
map it to F9:
map <f9> :%s/\s\+$//
search offset,
eg /foo/e+1
substituieren mit :s:
one substition per line *only*
substition flags:
g - the flag for global substitution
c - the flag for confirmation
deleting text: :%s/foo//
inserting text: :%s/foo/foobar/
adding insertion at the beginning of line:
s/^/foo/
adding insertion at the end of line:
s/$/foo/
reusing the match in the
replacement with ampersand:
:%s/foo/bar&/ -> barfoo
:%s/foo/&bar/ -> foobar
:%s/foo/&&/ -> foofoo
overlapping patterns:
v-------v
text: aaabbbcccddd
^-------^
:g/b.*d/s/a.*c/XXX/
global command (:g):
:g/RE/p
:g/RE/nu
:g/foo/d
show matches using
highlight search:
:set hls
toggling hls (on/off):
:set hls!
mapping it to f10:
map <f10> :set hls!<cr>
operate on all non-matching lines
with the command ":g!" or ":v":
:g!/foo/d
deletes all lines *not* containing "foo"
:v/./d
delete all lines which do not contain
at least one arbitrary chacrater ->
delete all empty lines
some more ex commands to apply:
:g/RE/co $ copy all RE lines to the end of buffer
:g/RE/mo $ move all RE lines to the end of buffer
:g/RE/ya a yank all RE lines into register a (note: overwrites each time!)
:g/RE/ya A yank all RE lines into register A (note: *appends* each time!)
combine commands :g und :s, eg for
commenting no-consecutive lines:
:g/echo/s/^/#
changing text in commented lines only:
:g/^\s*#/s:foo:bar:
== mutt:
set display_filter=script
set display_filter="/bin/sed -f sedscript"
set display_filter="/bin/sed -f ~/.mutt/df.sed"
== vim:
eingabe von spezielle zeichen
eingabe per ascii nummer:
-> :help i_CTRL-V
i_CTRL-V 233 -> é
eingabe per digraph command:
-> i_CTRL-K
i_CTRL-K a : -> ä
eingabe per digraph
mit ueberschreiben:
s CTRL-H s -> ß
geht nur mit ":set digraph"
-> :help 'digraph'
uebersicht der digraph kombinationen:
:dig
== agrep:
approximate grep
fehlertolerantes grep
big files with "signatures" -
grep all sigs by keyword
max length of RE: 8 chars.
=== Links
Jeffrey Friedl's Mastering Regular Expressions
http://regex.info/
Pattern (Java 2 Platform SE v1.4.2) - regex
http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
Regex for URLs
http://www.foad.org/~abigail/Perl/url2.html
C-SLang documentation (regex, too)
http://www.macroexpressions.com/doc/snob/snobre.htm
diese seite:
http://www.guckes.net/vortraege/abstract.workshop_regex.html
Latest change: Mon Feb 19 13:42:00 CET 2007