Sys Prog & Scrip - Heriot Watt Univ 1 Systems Programming & Scripting Lecture 12: Introduction to Scripting & Regular Expressions.

Slides:



Advertisements
Similar presentations
CSCI 330 T HE UNIX S YSTEM Regular Expressions. R EGULAR E XPRESSION A pattern of special characters used to match strings in a search Typically made.
Advertisements

ISBN Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl –(on reserve.
1 CSE 390a Lecture 7 Regular expressions, egrep, and sed slides created by Marty Stepp, modified by Jessica Miller and Ruth Anderson
CS 497C – Introduction to UNIX Lecture 29: - Filters Using Regular Expressions – grep and sed Chin-Chih Chang
1 CSE 303 Lecture 7 Regular expressions, egrep, and sed read Linux Pocket Guide pp , 73-74, 81 slides created by Marty Stepp
1 CSE 390a Lecture 7 Regular expressions, egrep, and sed slides created by Marty Stepp, modified by Jessica Miller
CS 497C – Introduction to UNIX Lecture 31: - Filters Using Regular Expressions – grep and sed Chin-Chih Chang
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/23.
Computational Language Finite State Machines and Regular Expressions.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
Regular Expressions. u A regular expression is a pattern which matches some regular (predictable) text. u Regular expressions are used in many Unix utilities.
Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl Linux editors and commands (e.g.
Topics Automata Theory Grammars and Languages Complexities
Regular Expressions Comp 2400: Fall 2008 Prof. Chris GauthierDickey.
Introduction to regular expression. Wéber André Objective of the training Scope of the course  We will present what are “regular expressions”
Filters using Regular Expressions grep: Searching a Pattern.
Shell Script Examples.
slides created by Marty Stepp
Regular Language & Expressions. Regular Language A regular language is one that a finite state machine (fsm) will accept. ‘Alphabet’: {a, b} ‘Rules’:
Last Updated March 2006 Slide 1 Regular Expressions.
System Programming Regular Expressions Regular Expressions
Globalisation & Computer systems Week 7 Text processes and globalisation part 1: Sorting strings: collation Searching strings and regular expressions Practical:
INFO 320 Server Technology I Week 7 Regular expressions 1INFO 320 week 7.
REGULAR EXPRESSIONS. Lexical Analysis Lexical analysers can be constructed by programs such as LEX These programs employ as input a description of the.
Regular Expressions Regular expressions are a language for string patterns. RegEx is integral to many programming languages:  Perl  Python  Javascript.
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.
Lexical Analysis I Specifying Tokens Lecture 2 CS 4318/5531 Spring 2010 Apan Qasem Texas State University *some slides adopted from Cooper and Torczon.
January 23, 2007Spring Unix Lecture 2 Special Characters for Searches & Substitutions Shell Scripts Hana Filip.
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.
Regular Expression - Intro Patterns that define a set of strings (or, pieces of a string) Not wildcards (similar notion, but different thing) Used by utilities.
Lecture 5 Regular Expressions CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Corpus Linguistics- Practical utilities (Lecture 7) Albert Gatt.
Regular Expressions for PHP Adding magic to your programming. Geoffrey Dunn
Regular Expressions What is this line all about? while (!($search =~ /^\s*$/)) { It’s a string search just like before, but with a huge twist – regular.
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
Regular Expressions CS 2204 Class meeting 6 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
CSCI 330 UNIX and Network Programming Unit IV Shell, Part 2.
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
-Joseph Beberman *Some slides are inspired by a PowerPoint presentation used by professor Seikyung Jung, which was derived from Charlie Wiseman.
Pattern Matching: Simple Patterns. Introduction Programmers often need to scan a file, directory, etc. for a specific substring. –Find all files that.
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Autumn 2012 CSE
ICS611 Lex Set 3. Lex and Yacc Lex is a program that generates lexical analyzers Converting the source code into the symbols (tokens) is the work of the.
Unix RE’s Text Processing Lexical Analysis.   RE’s appear in many systems, often private software that needs a simple language to describe sequences.
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
Regular expressions, egrep, and sed
Theory of Computation Lecture #
Regular expressions, egrep, and sed
Looking for Patterns - Finding them with Regular Expressions
CIRC Summer School 2017 Baowei Liu
Regular Expression - Intro
Regular expressions, egrep, and sed
Lecture 9 Shell Programming – Command substitution
Formal Language Theory
Week 14 - Friday CS221.
CSE 390a Lecture 7 Regular expressions, egrep, and sed
Folks Carelli, Instructor Kutztown University
CSE 390a Lecture 7 Regular expressions, egrep, and sed
Regular expressions, egrep, and sed
Regular expressions, egrep, and sed
CSE 303 Concepts and Tools for Software Development
Regular Expressions and Grep
CSCI The UNIX System Regular Expressions
Regular expressions, egrep, and sed
Regular expressions, egrep, and sed
CSE 390a Lecture 7 Regular expressions, egrep, and sed
Presentation transcript:

Sys Prog & Scrip - Heriot Watt Univ 1 Systems Programming & Scripting Lecture 12: Introduction to Scripting & Regular Expressions

Sys Prog & Scrip - Heriot Watt Univ 2 Goals of the Scripting Classes Learn how to easily do common operations on the command-line Learn how to generate simple scripts of repetitive activities Understand the structuring constructs available in the bash scripting language

Sys Prog & Scrip - Heriot Watt Univ 3 Non-Goals of Scripting Classes Give an introduction to Unix commands. Cover the full-range of bash Compare bash with other scripting languages (tcsh, python, …) Advocate scripting for large scale programming

Sys Prog & Scrip - Heriot Watt Univ 4 Introduction to Shell Scripting Scripts are sequences of repetitive commands, usually executed on the command-line. Scripting languages provide only an impoverished set of programming abstractions A focus of scripting languages is at easily combining simple commands to perform a more complex job. Powerful tools to achieve that are 'pipes' and 'regular expressions'.

Sys Prog & Scrip - Heriot Watt Univ 5 Regular Expressions Regular expressions provide a powerful, efficient and flexible text processing technique. They form the basis of text and data processing tools. They also commonly used to select files.

Sys Prog & Scrip - Heriot Watt Univ 6 History of Regular Expressions Based on mathematical notation developed by McCulloch and Pitts to describe neural networks. Formally introduced in 1956 by Kleene in his paper “Representation of Events in Nerve Nets” Ken Thompson, the inventor of Unix, used regular expressions in search algorithms. Their first practical use was in the Unix editor qed.

Sys Prog & Scrip - Heriot Watt Univ 7 Using Regular Expressions Integrated in many tools and languages – vi, grep, Perl, PHP. Facilitates a search engine. –Match upper and lower case. –Either or string matching. –Quantify character repeats. –Match classes of characters. –Match any character. –Expressions can be combined. –You can match anything using regular expressions. Syntax is simple.

Sys Prog & Scrip - Heriot Watt Univ 8 The Regular Expressions language Regular expressions are constructed using two types of characters: –Special characters or meta characters –Literal or normal text. Can think of regular expressions as a language: –Grammar: meta characters. –Words: literal text.

Sys Prog & Scrip - Heriot Watt Univ 9 Basic Syntax. The dot matches any single character –E.g. ab. matches aba, abb, abc, etc. [ ] A bracket expression matches a single character contained within the bracket. –E.g. [abc] matches a, b or c –[a-z] specifies a range which matches any lowercase letter from a to z. –[abcx-z] matches a, b, c, x, y and z.

Sys Prog & Scrip - Heriot Watt Univ 10 Cont. Basic Syntax [^ ] negation of [ ] –Matches a single character not contained in bracket. –E.g. [^abc] matches any character other than a, b or c. ^ matches the starting position of a string. $ matches the ending position of a string. * matches the previous element zero or more times. –E.g. abc*d matches abd, abcd, abccd, etc.

Sys Prog & Scrip - Heriot Watt Univ 11 POSIX regular expressions [:alnum:] matches alpha-numerical characters [:alpha:] matches alphabetical characters [:digit:] matches numerals [:upper:] matches upper case characters [:lower:] matches lower case characters

Sys Prog & Scrip - Heriot Watt Univ 12 Examples Searching (in) files Using find Using version control Doing stream processing with sed