Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Slides:



Advertisements
Similar presentations
CST8177 awk. The awk program is not named after the sea-bird (that's auk), nor is it a cry from a parrot (awwwk!). It's the initials of the authors, Aho,
Advertisements

Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Imagine if instead of cryptic, geeky text strings, your computer produced error messages in haiku...
การใช้ระบบปฏิบัติการ UNIX พื้นฐาน บทที่ 4 File Manipulation วิบูลย์ วราสิทธิชัย นักวิชาการคอมพิวเตอร์ ศูนย์คอมพิวเตอร์ ม. สงขลานครินทร์ เวอร์ชั่น 1 วันที่
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Josh Goodwin
Linux+ Guide to Linux Certification, Second Edition
Introduction to Unix – CS 21 Lecture 13. Lecture Overview Finding files and programs which whereis find xargs Putting it all together for some complex.
CS 497C – Introduction to UNIX Lecture 16: - File Attributes Chin-Chih Chang
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
QUOTATION This chapter teaches you about a unique feature of the shell programming language: the way it interprets quote characters. Basically, the shell.
Chapter 4: UNIX File Processing Input and Output.
1 Day 16 Sed and Awk. 2 Looking through output We already know what “grep” does. –It looks for something in a file. –Returns any line from the file that.
Introduction to UNIX/Linux Exercises Dan Stanzione.
Mechanics Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Advanced File Processing
Using the Unix Shell There is No ‘Undelete’. The Unix Shell “A Unix shell is a command-line interpreter or shell that provides a traditional user interface.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Guide to Linux Installation and Administration, 2e1 Chapter 7 The Role of the System Administrator.
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.
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
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.
(Stream Editor) By: Ross Mills.  Sed is an acronym for stream editor  Instead of altering the original file, sed is used to scan the input file line.
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.
Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.
Browsing Directories Copyright © Software Carpentry and The University of Edinburgh This work is licensed under the Creative Commons Attribution.
Quiz 30 minutes 10 questions No talking, texting, collaboration, etc…
Pipes and Filters Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Advanced Shell Tricks Copyright © The University of Southampton 2011 This work is licensed under the Creative Commons Attribution License See
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.
Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
More Tools Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Unix Shell Basics Edited from Greg Wilson's "Software Carpentry"
GREP. Whats Grep? Grep is a popular unix program that supports a special programming language for doing regular expressions The grammar in use for software.
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
Introduction to Linux Instructor: Bennett M. Tanyag PART – 3 Unit 1.
(Re)introduction to Unix Sarah Medland. So Unix…  Long and venerable history  
Getting the most out of the workshop Ask questions!!! Don’t sit next to someone you already know Work with someone with a different skillset and different.
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.
(Re)introduction to Unix Sarah Medland. So Unix…  Long and venerable history  
– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Introduction to the Shell – Session 3 · Job control · Start,
1 P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Awk Programming Ruibin Bai (Room AB326) Division of Computer Science The University.
Operators Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Basics Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
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.
Java Basics Regular Expressions.  A regular expression (RE) is a pattern used to search through text.  It either matches the.
Linux 201 Training Module Linux Adv File Mgmt.
Lesson 5-Exploring Utilities
CSE 374 Programming Concepts & Tools
CS 330 Class 7 Comments on Exam Programming plan for today:
The Command Prompt Commands are the way to “do things” in Unix
Lecture 9 Shell Programming – Command substitution
Introduction to computing
Basic UNIX OLC Training.
CSC 352– Unix Programming, Fall 2012
The ‘grep’ Command Colin Masterson.
Guide To UNIX Using Linux Third Edition
Chapter Four UNIX File Processing.
More advanced BASH usage
What is Unix? A multi-user networked operating system
Browsing Directories Using walk
Presentation transcript:

Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See for more information. The Unix Shell

Finding ThingsIntroduction shell

Finding ThingsIntroduction shell

Finding ThingsIntroduction shell Let's Google for that

Finding ThingsIntroduction shell Let's grep for that

Finding ThingsIntroduction grep: global / regular expression / print

Finding ThingsIntroduction grep: global / regular expression / print Finds and prints lines in files that match a pattern

Finding ThingsIntroduction grep: global / regular expression / print Finds and prints lines in files that match a pattern The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. haiku.txt

Finding ThingsIntroduction grep: global / regular expression / print Finds and prints lines in files that match a pattern The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. haiku.txt $ grep not haiku.txt

Finding ThingsIntroduction grep: global / regular expression / print Finds and prints lines in files that match a pattern The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. haiku.txt $ grep not haiku.txt Pattern

Finding ThingsIntroduction grep: global / regular expression / print Finds and prints lines in files that match a pattern The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. haiku.txt $ grep not haiku.txt Pattern Every letter matches itself

Finding ThingsIntroduction grep: global / regular expression / print Finds and prints lines in files that match a pattern The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. haiku.txt $ grep not haiku.txt File(s)

Finding ThingsIntroduction grep: global / regular expression / print Finds and prints lines in files that match a pattern The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. haiku.txt $ grep not haiku.txt Is not the true Tao, until "My Thesis" not found Today it is not working $

Finding ThingsIntroduction The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. $ grep day haiku.txt Yesterday it worked Today it is not working $

Finding ThingsIntroduction The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. $ grep day haiku.txt Yesterday it worked Today it is not working $ grep -w day haiku.txt $ Match whole words

Finding ThingsIntroduction The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. $ grep day haiku.txt Yesterday it worked Today it is not working $ grep -w day haiku.txt $ grep -n it haiku.txt Prefix matches with line numbers

Finding ThingsIntroduction The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. $ grep day haiku.txt Yesterday it worked Today it is not working $ grep -w day haiku.txt $ grep -n it haiku.txt 5:With searching comes loss 9:Yesterday it worked 10:Today it is not working $

Finding ThingsIntroduction The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. $ grep day haiku.txt Yesterday it worked Today it is not working $ grep -w day haiku.txt $ grep -n it haiku.txt 5:With searching comes loss 9:Yesterday it worked 10:Today it is not working $ grep -w -n it haiku.txt Use multiple flags to combine effects

Finding ThingsIntroduction The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. $ grep day haiku.txt Yesterday it worked Today it is not working $ grep -w day haiku.txt $ grep -n it haiku.txt 5:With searching comes loss 9:Yesterday it worked 10:Today it is not working $ grep -w -n it haiku.txt 9:Yesterday it worked 10:Today it is not working $

Finding ThingsIntroduction The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. $ grep -i -v the haiku.txt You bring fresh toner. With searching comes loss Yesterday it worked Today it is not working Software is like that. $

Finding ThingsIntroduction The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. $ grep -i -v the haiku.txt You bring fresh toner. With searching comes loss Yesterday it worked Today it is not working Software is like that. $ -icase insensitive

Finding ThingsIntroduction The Tao that is seen Is not the true Tao, until You bring fresh toner. With searching comes loss and the presence of absence: "My Thesis" not found. Yesterday it worked Today it is not working Software is like that. $ grep -i -v the haiku.txt You bring fresh toner. With searching comes loss Yesterday it worked Today it is not working Software is like that. $ -icase insensitive -vinvert and print non-matches

Finding ThingsIntroduction Many more options

Finding ThingsIntroduction Many more options Use man grep to get help

Finding ThingsIntroduction Many more options Use man grep to get help manual

Finding ThingsIntroduction Many more options Use man grep to get help Complex patterns use regular expressions

Finding ThingsIntroduction Many more options Use man grep to get help Complex patterns use regular expressions (The 're' in grep)

Finding ThingsIntroduction Many more options Use man grep to get help Complex patterns use regular expressions (The 're' in grep) Ideas are covered in a separate lecture

Finding ThingsIntroduction Many more options Use man grep to get help Complex patterns use regular expressions (The 're' in grep) Ideas are covered in a separate lecture grep's regular expressions are slightly different from those provided in most programming languages

Finding ThingsIntroduction Many more options Use man grep to get help Complex patterns use regular expressions (The 're' in grep) Ideas are covered in a separate lecture grep's regular expressions are slightly different from those provided in most programming languages But the ideas are the same

Finding ThingsIntroduction find: finds files (rather than lines in files)

Finding ThingsIntroduction find: finds files (rather than lines in files) Again, too many options to cover here

Finding ThingsIntroduction find: finds files (rather than lines in files) Again, too many options to cover here vlad datatoolsthesisnotes.txt first.txt second.txt format stats old

Finding ThingsIntroduction find: finds files (rather than lines in files) Again, too many options to cover here./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* Output of tree

Finding ThingsIntroduction find: finds files (rather than lines in files) Again, too many options to cover here./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* Output of tree Trailing / shows directories

Finding ThingsIntroduction find: finds files (rather than lines in files) Again, too many options to cover here./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* Output of tree Trailing / shows directories Trailing * shows executables

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -type d

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -type d Root directory of search

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -type d Things of type 'd' (directory)

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -type d././data./thesis./tools./tools/old $

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -type d././data./thesis./tools./tools/old $ find. -type f./data/first.txt./data/second.txt./notes.txt./tools/format./tools/stats $

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -maxdepth 1 -type f./notes.txt $

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -maxdepth 1 -type f./notes.txt $ find. -mindepth 2 -type f./data/first.txt./data/second.txt./tools/format./tools/stats $

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -maxdepth 1 -type f./notes.txt $ find. -mindepth 2 -type f./data/first.txt./data/second.txt./tools/format./tools/stats $ find. -empty./thesis./tools/old $

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -perm -u=x./data./thesis./tools./tools/format./tools/old./tools/stats $

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -perm -u=x./data./thesis./tools./tools/format./tools/old./tools/stats $ find. -perm -u=x -type f./tools/format./tools/stats $

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -name *.txt./notes.txt $

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -name *.txt./notes.txt $ * expanded by shell before command runs

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -name notes.txt./notes.txt $ * expanded by shell before command runs This is the actual command

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -name *.txt./notes.txt $ find. -name '*.txt' Single quotes prevent shell from expanding wildcards

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -name *.txt./notes.txt $ find. -name '*.txt' Single quotes prevent shell from expanding wildcards So find gets the pattern

Finding ThingsIntroduction./ +-- data/ | +-- first.txt | +-- second.txt +-- notes.txt +-- thesis/ +-- tools/ +-- format* +-- old/ +-- stats* $ find. -name *.txt./notes.txt $ find. -name '*.txt'./data/first.txt./data/second.txt./notes.txt $

Finding ThingsIntroduction The command line's power lies in combining tools

Finding ThingsIntroduction The command line's power lies in combining tools $ find. -name '*.txt'./data/first.txt./data/second.txt./notes.txt $

Finding ThingsIntroduction The command line's power lies in combining tools $ find. -name '*.txt'./data/first.txt./data/second.txt./notes.txt $ wc -l `find. -name '*.txt'`

Finding ThingsIntroduction The command line's power lies in combining tools $ find. -name '*.txt'./data/first.txt./data/second.txt./notes.txt $ wc -l `find. -name '*.txt'` Back quotes

Finding ThingsIntroduction The command line's power lies in combining tools $ find. -name '*.txt'./data/first.txt./data/second.txt./notes.txt $ wc -l `find. -name '*.txt'` Back quotes Replace what's inside with output from running that command

Finding ThingsIntroduction The command line's power lies in combining tools $ find. -name '*.txt'./data/first.txt./data/second.txt./notes.txt $ wc -l `find. -name '*.txt'` Back quotes Replace what's inside with output from running that command Like wildcards * and ?, but more flexible

Finding ThingsIntroduction The command line's power lies in combining tools $ find. -name '*.txt'./data/first.txt./data/second.txt./notes.txt $ wc -l `find. -name '*.txt'`./data/first.txt./data/second.txt./notes.txt

Finding ThingsIntroduction The command line's power lies in combining tools $ find. -name '*.txt'./data/first.txt./data/second.txt./notes.txt $ wc -l `find. -name '*.txt'` $ wc -l./data/first.txt./data/second.txt./notes.txt

Finding ThingsIntroduction The command line's power lies in combining tools $ find. -name '*.txt'./data/first.txt./data/second.txt./notes.txt $ wc -l `find. -name '*.txt'` 70./data/first.txt 420./data/second.txt 30./notes.txt 520 total $

Finding ThingsIntroduction Use find and grep together

Finding ThingsIntroduction Use find and grep together $ grep FE `find. -name '*.pdb'`./human/heme.pdb:ATOM 25 FE $

Finding ThingsIntroduction What if your data isn't text?

Finding ThingsIntroduction What if your data isn't text? Images, databases, spreadsheets…

Finding ThingsIntroduction What if your data isn't text? Images, databases, spreadsheets… 1.Teach standard tools about all these formats

Finding ThingsIntroduction What if your data isn't text? Images, databases, spreadsheets… 1.Teach standard tools about all these formats Hasn't happened, and probably won't

Finding ThingsIntroduction What if your data isn't text? Images, databases, spreadsheets… 1.Teach standard tools about all these formats Hasn't happened, and probably won't 2.Convert data to text (or extract text from data)

Finding ThingsIntroduction What if your data isn't text? Images, databases, spreadsheets… 1.Teach standard tools about all these formats Hasn't happened, and probably won't 2.Convert data to text (or extract text from data) Simple things are easy

Finding ThingsIntroduction What if your data isn't text? Images, databases, spreadsheets… 1.Teach standard tools about all these formats Hasn't happened, and probably won't 2.Convert data to text (or extract text from data) Simple things are easy Complex things are impossible

Finding ThingsIntroduction What if your data isn't text? Images, databases, spreadsheets… 1.Teach standard tools about all these formats Hasn't happened, and probably won't 2.Convert data to text (or extract text from data) Simple things are easy Complex things are impossible 3.Use a programming language

Finding ThingsIntroduction What if your data isn't text? Images, databases, spreadsheets… 1.Teach standard tools about all these formats Hasn't happened, and probably won't 2.Convert data to text (or extract text from data) Simple things are easy Complex things are impossible 3.Use a programming language Many have borrowed ideas from the shell

August 2010 created by Greg Wilson Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See for more information.