1 / 9

CS311 – Lecture 04 Outline

CS311 – Lecture 04 Outline. Bash scripting Understand the script2 script Understand the myWC script grep - find pattern matches REG ular EX pressions sed : stream editing

nadine
Download Presentation

CS311 – Lecture 04 Outline

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS311 – Lecture 04 Outline • Bash scripting • Understand the script2 script • Understand the myWC script • grep - find pattern matches • REGular EXpressions • sed: stream editing Note: These lecture notes are not intended replace your notes. This is what I expect your notes to already look like, but with more explanation as needed. CS311 – Operating Systems 1 1

  2. Bash scripting language #! /bin/sh shebang lines ' vs " vs \ quoting ` ` command substitution $# bash variable for how many command line args were given $1 bash variable that retrieves the 1st command line arg. $USER environmental variable, your username exit bash builtin for exiting bash CS311 – Operating Systems 1 2

  3. Flow control statements Lecture 02 • if statements • use test utility to test for equality or < or > or if a file exists. • for loops CS311 – Operating Systems 1 3 3

  4. grep - find pattern matches Grep filters lines of text based on patterns grep [options] pattern [file] This util allows a filename. But, of course, you can send it input through pipes or <. CS311 – Operating Systems 1 4

  5. REGular EXpressions Regular expressions are character sequences that describe a family of matching strings every letter matches itself ^ - start of line, or negation of characters (if it is in []) $ - end of line . - any character [] – range, or set of characters * - any number of times + - at least once ? - exactly once CS311 – Operating Systems 1 5

  6. REGular EXpressions echo "cowboys" | grep ".*" echo "cowboys" | grep ". . . . . . ." echo "cowboys" | grep "c.*s" echo "cowgirls" | grep "c.*s" echo "tomboys" | grep "c.*" echo "aaabb" | grep "^a*b*$" echo "bbbb" | grep "^a*b*$" echo "ccbbb" | grep "^a*b*$" echo "aabbb" | grep "^a+b*$" echo "bbb" | grep "^a+b*$" yes yes yes yes no yes yes no yes no CS311 – Operating Systems 1 6

  7. REGular EXpressions echo "cowboy" | grep "^[a-z]*$" echo "cowboy123" | grep "^[a-z]*$" echo "cowboy123" | grep "^[a-z]*[0-9]*$" echo "cowboy" | grep "^[bcowy]*$" yes no yes yes Lecture 04 CS311 – Operating Systems 1 7 7

  8. grep - find pattern matches • Useful options • -E • -c • -o • -n • -i CS311 – Operating Systems 1 8

  9. sed -r "s/regex/text/g" filename substitute every occurrence of the regular expressions regex by the string text. CS311 – Operating Systems 1 9

More Related