CS 403: Programming Languages Lecture 21 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Slides:



Advertisements
Similar presentations
EMT 2390L Lecture 4 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
Advertisements

Introduction to UNIX CSE 2031 Fall May 2015.
 *, ? And [ …] . Any single character  ^ beginning of a line  $ end of the line.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
CS 497C – Introduction to UNIX Lecture 25: - Simple Filters Chin-Chih Chang
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Introduction to UNIX GPS Processing and Analysis with GAMIT/GLOBK/TRACK T. Herring, R. King. M. Floyd – MIT UNAVCO, Boulder - July 8-12, 2013 Directory.
Unix Filters Text processing utilities. Filters Filter commands – Unix commands that serve dual purposes: –standalone –used with other commands and pipes.
UNIX Filters.
CS 124/LINGUIST 180 From Languages to Information Unix for Poets (in 2014) Dan Jurafsky (From Chris Manning’s modification of Ken Church’s presentation)
Shell Script Examples.
Advanced File Processing
Writing Shell Scripts ─ part 1 CSE 2031 Fall September 2015.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
LIN 6932 Unix Lecture 6 Hana Filip. LIN 6932 HW6 - Part II solutions posted on my website see syllabus.
Unix programming Term: III B.Tech II semester Unit-II PPT Slides Text Books: (1)unix the ultimate guide by Sumitabha Das (2)Advanced programming.
Regular expressions Used by several different UNIX commands, including ed, sed, awk, grep A period ‘.’ matches any single characters.X. matches any X.
CS 403: Programming Languages Fall 2004 Department of Computer Science University of Alabama Joel Jones.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Writing Shell Scripts ─ part 3 CSE 2031 Fall October 2015.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Chapter Five Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
Introduction to Unix – CS 21 Lecture 6. Lecture Overview Homework questions More on wildcards Regular expressions Using grep Quiz #1.
CSC 352– Unix Programming, Spring 2015 April 28 A few final commands.
Awk Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
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.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
Chapter Four I/O Redirection1 System Programming Shell Operators.
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
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
CS 124/LINGUIST 180 From Languages to Information Unix for Poets (in 2013) Christopher Manning Stanford University.
– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Introduction to the Shell – Session 3 · Job control · Start,
CS 124/LINGUIST 180 From Languages to Information
1 Lecture 10 Introduction to AWK COP 3344 Introduction to UNIX.
ORAFACT Text Processing. ORAFACT Searching Inside Files grep - searches for patterns within files grep [options] [[-e] pattern] filename [...] -n shows.
Uniq The uniq command is useful when you need to find duplicate lines in a file. The basic format of the command is uniq in_file out_file In this format,
Lesson 6-Using Utilities to Accomplish Complex Tasks.
In the last class, Filters and delimiters The sample database pr command head and tail commands cut and paste commands.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 UNIX Operating Systems II Part 2: Shell Scripting Instructor: Stan Isaacs.
6/13/2016Course material created by D. Woit 1 CPS 393 Introduction to Unix and C START OF WEEK 3 (UNIX) 6/13/2016Course material created by D. Woit 1.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
Filters and Utilities. Notes: This is a simple overview of the filtering capability Some of these commands are very powerful ▫Only showing some of the.
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Tutorial of Unix Command & shell scriptS 5027
Lesson 5-Exploring Utilities
CST8177 sed The Stream Editor.
The UNIX Shell Learning Objectives:
Part 1: Basic Commands/Utilities
Chapter 6 Filters.
Lecture 9 Shell Programming – Command substitution
Unix Scripting Session 4 March 27, 2008.
CS 403: Programming Languages
INTRODUCTION TO UNIX: The Shell Command Interface
Writing Shell Scripts ─ part 3
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Tutorial of Unix Command & shell scriptS 5027
What is Bash Shell Scripting?
Guide To UNIX Using Linux Third Edition
Tutorial of Unix Command & shell scriptS 5027
Lab 7: Filtering.
CSC 4630 Meeting 4 January 29, 2007.
Introduction to Bash Programming, part 3
Software I: Utilities and Internals
Presentation transcript:

CS 403: Programming Languages Lecture 21 Fall 2003 Department of Computer Science University of Alabama Joel Jones

Lecture 212 Overview Announcements Story Hour, Houser 108, 3PM Friday Colloquium, Houser 108, 11PM Monday, received his Ph.D. from UA. Prof. Nenad Jukic Loyola University Chicago. “Comprehensive Data Warehouse Exploration: Extending the Scope of Association-Rule Mining” MP2 Shell Programming Substitution Sub-shells, background mode, job control Quoting Regular Expressions and filters

Final version of which # which cmd: which cmd in PATH is executed, final version opath=$PATH PATH=/bin:/usr/bin case $# in 0) echo ‘Usage: which command’ 1>&2; exit 2 esac for i in `echo $opath | sed ‘s/^:/.:/ s/::/:.:/g s/:$/:./ s/:/ /g’` do if test -f $i/$1 then echo $i/$1 # found it exit 0 fi done exit 1 # not found

Lecture 214 $ cat makeHTML cat << EOF Hello $1 $2 EOF $ makeHTML Joel Jones Hello Joel Jones Another way of doing substitution In contrast to <<‘s’ which does no substitution $ cat makeHTML2 cat << ‘EOF’ Hello $1 $2 EOF $ makeHTML2 Joel Jones Hello $1 $2

Programs that write programs $ cat bundle # bundle: group files into distribution package echo '# to unbundle, sh this file' for i do echo "echo $i 1>&2" echo "cat >$i <<'End of $i'" cat $i echo "End of $i" done $./bundle makeHTML makeHTML2 > junk $ cat junk # to unbundle, sh this file echo makeHTML 1>&2 cat >makeHTML <<'End of makeHTML' cat << EOF Hello $1 $2 EOF End of makeHTML echo makeHTML2 1>&2 cat >makeHTML2 <<'End of makeHTML2' cat << 'EOF' Hello $1 $2 EOF End of makeHTML2

Lecture 216 Sub-shells, background mode, and job control $ sleep 5 $ $ (sleep 5; date) & date [1] 2682 Thu Nov 13 00:19:31 CST 2003 $ Thu Nov 13 00:19:36 CST 2003 $ (sleep 300; echo Tea is ready) & [1] 2684 $jobs [1] + Running (sleep 300; echo Tea is ready) & $ kill %1 [1] + Terminated (sleep 300; echo Tea is ready) & $

Lecture 217 Some examples of quoting $ date Thu Nov 13 00:28:08 CST 2003 $ echo "The time is `date`" Pair Up: What is the output? $ `date` Pair Up: What is the output? $ echo `echo \`date\`` Pair Up: What is the output?

Lecture 218 Filters $ ls -l total 32 -rwxr--r-- 1 jones staff 203 Nov 13 00:09 bundle -rw-r--r-- 1 jones staff 240 Nov 13 00:10 junk -rwxr--r-- 1 jones staff 34 Nov 13 00:00 makeHTML -rwxr--r-- 1 jones staff 36 Nov 13 00:04 makeHTML2 drwxr-xr-x 2 jones staff 68 Nov 13 00:41 subdir $ ls -l | grep ‘^d’ Pair Up: What is the output?

Lecture 219 Regular Expressions and Filters $ tail -3 /usr/share/dict/web2 zythum Zyzomys Zyzzogeton $ Pair Up: write a grep command to find all words that contain all fives vowels, in order, e.g. abstemious. Format: grep pattern file* Grep Regular Expressions cAny non-special character c matches itself ^Beginning of line $End of line […]Any one of the characters in …; ranges like a-z are legal [^…]Any single character not in …; ranges are legal r*Zero or more occurrences of r

Lecture 2110 Pair Up: Write a sort command that prints unique lines doing a case insensitive comparison. Other Filters Sort has lots of options -f folds upper and lower case -n sorts by numeric value -r reverses order +m skips first m fields, +0 stands for entire line -u (unique) removes adjacent duplicate lines Multiple field specifications do lexigraphic sorting—lines considered equal by earlier sorts are grouped and kept together as subsequent sorts sort each group sort +0f +0 -u filenames

Lecture 2111 Other Filters (cont.) tr inputChars outputChar(s) tr a-z A-Z maps lower case to upper case Flags: -s squeezes multiple occurences of a character in the input to a single character in the output; -c takes the complement of the first argument, e.g. tr -c ab matches every character except a and b. tr also understands character ranges. uniq removes duplicate adjacent lines Flags: -c adds count of duplicate lines at beginning ‘\012’ is a new line Pair Up: Write a pipeline that prints the 10 most frequent words in its input.

Lecture 2112 Printing 10 most common words cat $* | # tr doesn’t take filename arguments tr -sc A-Za-z ‘\012’ | # all non alpha become newline sort | uniq -c | # get the count sort -n | # sort by count tail # prints 10 by default Use the man command to look at for help man sort