CIRC Summer School 2017 Baowei Liu

Slides:



Advertisements
Similar presentations
CST8177 sed The Stream Editor. The original editor for Unix was called ed, short for editor. By today's standards, ed was very primitive. Soon, sed was.
Advertisements

2006-Jan-231 Shell Scripts Jacob Morzinski
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Linux+ Guide to Linux Certification, Second Edition
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
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.
23-Jun-15Advanced Programming Spring 2002 bash Henning Schulzrinne Department of Computer Science Columbia University.
Guide To UNIX Using Linux Third Edition
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
Filters using Regular Expressions grep: Searching a Pattern.
Shell Script Examples.
Chapter 4: UNIX File Processing Input and Output.
3 File Processing Mauro Jaskelioff. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Guide To UNIX Using Linux Fourth Edition
1 Shell Programming – Extra Slides. 2 Counting the number of lines in a file #!/bin/sh #countLines1 filename=$1#Should check if arguments are given count=0.
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.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 8 Shell.
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Linux+ Guide to Linux Certification, Third Edition
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
CSC 352– Unix Programming, Spring 2015 April 28 A few final commands.
Lesson 2 1.Commands 2.Filename Substitution 3.I/O Redirection 4.Command Grouping 5.Shell Responisibilites Review of the Basics.
I/O Redirection and Regular Expressions February 9 th, 2004 Class Meeting 4.
Introduction to sed. Sed : a “S tream ED itor ” What is Sed ?  A “non-interactive” text editor that is called from the unix command line.  Input text.
Chapter Four I/O Redirection1 System Programming Shell Operators.
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
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
Linux+ Guide to Linux Certification, Second Edition
Introduction to Bash Shell. What is Shell? The shell is a command interpreter. It is the layer between the operating system kernel and the user.
ORAFACT Text Processing. ORAFACT Searching Inside Files grep - searches for patterns within files grep [options] [[-e] pattern] filename [...] -n shows.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
CSC 352– Unix Programming, Fall 2011 November 8, 2011, Week 11, a useful subset of regular expressions, grep and sed, parts of Chapter 11.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Linux Administration Working with the BASH Shell.
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.
Introduction to the bash Shell (Bourne-Again SHell)
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
CIRC Summer School 2016 Baowei Liu
CIRC Winter Boot Camp 2017 Baowei Liu
CSC 352– Unix Programming, Spring 2016
Shell Features CSCI N321 – System and Network Administration
CST8177 sed The Stream Editor.
CIRC Winter Boot Camp 2017 Baowei Liu
CIRC Summer School 2017 Baowei Liu
Lecture 9 Shell Programming – Command substitution
CSE 303 Concepts and Tools for Software Development
Tutorial of Unix Command & shell scriptS 5027
CSC 352– Unix Programming, Fall 2012
Tutorial of Unix Command & shell scriptS 5027
CSC 352– Unix Programming, Spring 2016
Tutorial of Unix Command & shell scriptS 5027
Unix Talk #2 (sed).
Chapter Four UNIX File Processing.
CSE 390a Lecture 7 Regular expressions, egrep, and sed
More advanced BASH usage
Regular Expressions and Grep
CSC 4630 Meeting 4 January 29, 2007.
CSE 390a Lecture 7 Regular expressions, egrep, and sed
LPI Linux Certification
Presentation transcript:

CIRC Summer School 2017 Baowei Liu 7.25.2017 Bash Scripting CIRC Summer School 2017 Baowei Liu 7.25.2017

Stdin, stdout and stderr File descriptor(FD): a handle to access a file Stdin: standard input stream (e.g. keyboard) –FD:0 Stdout: standard output stream (e.g. monitor) –FD:1 Stderr: standard error output stream (usually also on monitor) ) –FD:2

I/O Redirection: Redirecting to a file Redirect between files including the three file descriptors, stdin, stdout and stder Redirecting output: date > file Appending redirecting output: date >> file Redirecting input: Command < input

I/O Redirection: Pipes Pipes connect the standard output of one command to the standard input of another with the pipe symbol |. command1 | command2

Positional Parameters Arguments given to bash script when it is invoked $1, $2 … $N. ${N} if N>9 $0 is the base-name of the script $# is the total arguments given Example: shareFiles.sh positionalParameters.sh

grep grep: search for matches to a pattern in a file and print the matched line to stdout grep Pattern file Pattern could be simple strings or regular expressions

Regular Expression Regular Expression: globbing pattern used for text . : Equivalent to ? in filename expansion * : zero or more times, aa* will match a,aa,…but not ab .*: any string. Equivalent to * in filename expansion ^: starting with, ^ab $: ending with, ab$

Regular Expression []: “-” \< \>: exact word

sed and Regular Expressions Stream editor for parses and transform text sed ‘s/abc/xyz/’ File: first occurrences sed ‘5,10s/abc/xyz/’ File: range, specified lines Sed ‘0~2 s/abc/xyz/’ File: Every other line starting 0 or even lines

sed and Regular Expressions Word Characters: Alphanumeric characters plus “_” [A-Za-z0-9_] Replace all occurrences in a line

More Examples Wrappers

Project Write a Bash script to black out sensitive information buried in all but the .data files under files/ (i.e. ONLY the html,xml,txt files) Key tech: editor, chmod, command substitution, for loop, echo, case/if, string compare, substring remove, sed, regular expression, i/o redirection