CSE 303 Concepts and Tools for Software Development

Slides:



Advertisements
Similar presentations
An Introduction to Sed & Awk Presented Tues, Jan 14 th, 2003 Send any suggestions to Siobhan Quinn
Advertisements

7 Searching and Regular Expressions (Regex) Mauro Jaskelioff.
ISBN Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl –(on reserve.
Quotes: single vs. double vs. grave accent % set day = date % echo day day % echo $day date % echo '$day' $day % echo "$day" date % echo `$day` Mon Jul.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Filters using Regular Expressions grep: Searching a Pattern.
System Programming Regular Expressions Regular Expressions
Unix Talk #2 (sed). 2 You have learned…  Regular expressions, grep, & egrep  grep & egrep are tools used to search for text in a file  AWK -- powerful.
Perl and Regular Expressions Regular Expressions are available as part of the programming languages Java, JScript, Visual Basic and VBScript, JavaScript,
Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command to search for.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
CSE 311 Foundations of Computing I Lecture 17 Structural Induction: Regular Expressions, Regular Languages Autumn 2011 CSE 3111.
Introduction to Unix – CS 21 Lecture 6. Lecture Overview Homework questions More on wildcards Regular expressions Using grep Quiz #1.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
I/O Redirection and Regular Expressions February 9 th, 2004 Class Meeting 4.
Introduction to Unix – CS 21 Lecture 12. Lecture Overview A few more bash programming tricks The here document Trapping signals in bash cut and tr sed.
CSE 311 Foundations of Computing I Lecture 17 Structural Induction Spring
Pattern Matching CSCI N321 – System and Network Administration.
Appendix A: Regular Expressions It’s All Greek to Me.
Sys Prog & Scrip - Heriot Watt Univ 1 Systems Programming & Scripting Lecture 12: Introduction to Scripting & Regular Expressions.
40 Years and Still Rocking the Terminal!
I/O Redirection & Regular Expressions CS 2204 Class meeting 4 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Advanced Text Processing. 222 Lecture Overview  Character manipulation commands cut, paste, tr  Line manipulation commands sort, uniq, diff  Regular.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Regular Expressions.
CSCI 330 UNIX and Network Programming Unit IV Shell, Part 2.
CSCI 330 UNIX and Network Programming Unit IV Shell, Part 2.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 6 – sed, command-line tools wrapup.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 5 – Regular Expressions, grep, Other Utilities.
Standard Types and Regular Expressions CS 480/680 – Comparative Languages.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 4 – Shell Variables, More Shell Scripts.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
-Joseph Beberman *Some slides are inspired by a PowerPoint presentation used by professor Seikyung Jung, which was derived from Charlie Wiseman.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
CMSC330 More Ruby. Last lecture Scripting languages Ruby language –Implicit variable declarations –Many control statements –Classes & objects –Strings.
CS:414 INTRODUCTION TO UNIX AND LINUX Part 3: Regular Expressions and vi editor By Dr. Noman Hasany.
Copyright 2009 der.hans intro over a decade as sysadmin, programmer, analyst, data janitor currently director of engineering for a startup adjunct instructor.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/9/2006 Lecture 6 – String Processing.
CIRC Summer School 2016 Baowei Liu
PROGRAMMING THE BASH SHELL PART III by İlker Korkmaz and Kaya Oğuz
Regular Expressions Copyright Doug Maxwell (
Lesson 5-Exploring Utilities
CSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools
CSC 352– Unix Programming, Spring 2016
Looking for Patterns - Finding them with Regular Expressions
Regular Expressions in Perl
Regular Expression - Intro
Lecture 9 Shell Programming – Command substitution
CSE 311 Foundations of Computing I
Grep Allows you to filter text based upon several different regular expression variants Basic Extended Perl.
CS 403: Programming Languages
CSE 303 Concepts and Tools for Software Development
CSC 352– Unix Programming, Fall 2012
Folks Carelli, Instructor Kutztown University
Guide To UNIX Using Linux Third Edition
CSC 352– Unix Programming, Spring 2016
Unix Talk #2 grep/egrep/fgrep (maybe add more to this one….)
Unix Talk #2 (sed).
CSE 303 Concepts and Tools for Software Development
Regular Expressions and Grep
CSE 303 Concepts and Tools for Software Development
CIT 383: Administrative Scripting
CSCI The UNIX System Regular Expressions
Regular Expressions grep Familiy of Commands
Lab 8: Regular Expressions
LPI Linux Certification
Regular Expressions.
Presentation transcript:

CSE 303 Concepts and Tools for Software Development CSE 303 Lecture 5 10/6/2006 CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/6/2006 Lecture 5 – Regular Expressions

Administravia Homework 1 is due! 10/6/2006 CSE 303 Lecture 5

Tip of the Day Viewing Multiple buffers in Emacs C-x 2 : Make two buffers visible C-x o : Switch cursor to “other” buffer Careful! This also switches from mini-buffer! C-x 1 : Make current buffer the only buffer 10/6/2006 CSE 303 Lecture 5

Where are we? Tons of info on the shell Coming up Pseudo-programming language Files, users, and processes You know just enough to get around Coming up More powerful ideas 10/6/2006 CSE 303 Lecture 5

Today Regular Expressions Other Utilities Find strings matching a pattern Recurring theme in CS theory Crisp, elegant, and useful idea Powerful tool for computer science Less educated hackers don’t tend to know Other Utilities find, diff, wc 10/6/2006 CSE 303 Lecture 5

Types of Regular Expressions “Globbing” = filename expansion “Regular Expressions” = pattern matching In CSE 322 (finite automata) In grep In egrep Others… 10/6/2006 CSE 303 Lecture 5

What are Regular Expressions? Recursive definition: p = … a, b, c : matches a single character p1p2 : matches if p1 comes just before p2 (p1|p2) : matches either p1 or p2 p* : matches 0 or more instances of p Example Match abcbdgef against bd(e|g)* 10/6/2006 CSE 303 Lecture 5

Why This Language? Amazing Facts For more of this, see CSE 322 Such patterns are very easy to match Space/time scale nicely with length of input and regexp Know space needed before matching! Can tell if two regexps match same strings For more of this, see CSE 322 10/6/2006 CSE 303 Lecture 5

More Regular Expressions Syntactic Conveniences p+ = pp* (one or more p’s) p? = (|p) (zero or one p) [zd-h] = z | d | e | f | g | h [^A-Z] = … (any not in set) . = … (any character) p{n} = … (n instances of p) p{n,} = … (n or more p’s) p{n,m} = … (from n to n+m instances of p) 10/6/2006 CSE 303 Lecture 5

More Regular Expressions Other Conveniences [:alnum:] = Letters and Numbers [:alpha:] = Letters [:digit:] = Numbers [:lower:] = Lowercase letters [:print:] = Printable characters [:punct:] = Punctuation Marks [:space:] = Whitespace 10/6/2006 CSE 303 Lecture 5

grep finds patterns in files grep p [file] Reads each line from stdin (or file) If match, print line on stdout Technically, matches against .*p.* Get rid of 1st .* with ^ Get rid of 2nd .* with $ Example: ^p$ matches whole line exactly 10/6/2006 CSE 303 Lecture 5

Regular Expression Gotchas Check syntax of each program grep uses \| \+ \? \{ \} egrep uses | + ? { } Use quotes to avoid shell substitutions Escape special characters with \ \. and . are very different! Rules different inside [ ] (\ is literal) 10/6/2006 CSE 303 Lecture 5

Reusing Previous Matches Can refer to matches of previous ( ) \n refers to match of nth ( ) Example: Double-words ^([a-zA-Z]+)\1$ Very useful when doing substitution We’ll see this next time 10/6/2006 CSE 303 Lecture 5

Other Utilities Put these in your arsenal find : search a directory tree for anything Linux Pocket Guide gives nice summary find . –type f – name “foo.*” – exec grep “regexp” “{}” \; - print diff : compare two files or directories wc : count the bytes, words, lines in a file 10/6/2006 CSE 303 Lecture 5

Summary Regular Expressions Other Utilities Powerful and useful idea Powerful tool for computer science Less educated hackers don’t tend to know Other Utilities find diff wc 10/6/2006 CSE 303 Lecture 5

Reading Linux Pocket Guide p71-74 (grep) p66-68 (find) p86-88 (diff) p58 (wc) 10/6/2006 CSE 303 Lecture 5

Next Time Other scripting tools sed : For changing text files awk : More powerful text editing General-purpose scripting languages perl python ruby 10/6/2006 CSE 303 Lecture 5