{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs2042_Lecture5

cs2042_Lecture5 - CS2042 Unix Tools Fall 2009 Lecture 5...

Info icon This preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CS2042 - Unix Tools Fall 2009 Lecture 5 David Slater dms236 at cornell.edu October 7, 2009 David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Organization I will hand out Homework 2 at the end of class David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 2
And now it gets interesting... grep The purpose of grep is to print the lines that match a particular pattern. grep grep <string> [file] searches file for all lines containing <string> grep stands for global / regular expression / print Examples: grep password file prints all lines that contain the word password in the file file . What lines contain the word monster in Frankenstein? grep ’monster’ Frankenstein.txt David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
More Simple Examples Two simple ways to use grep are on a file and on piped input: grep on a file grep "chromium" /var/log/dpkg.log Shows when I have updated chromium-browser grep piped input history | grep grep When have I used grep recently? David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 4
Grep options grep -i - ignores case grep -A 20 -B 10 - prints the 10 lines before and 20 lines after each match grep -v - inverts the match grep -o - shows only the matched substring grep -n - displays the line number Example: grep -v # bashscript Prints all noncommented lines David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Regular Expression grep like many programs takes in a regular expression as its input. Pattern matching with regular expressions is more sophisticated than shell expansion and also uses different syntax. More precisely, a regular expression is a set of strings; these strings match the expression. When we use regular expressions, it is (usually) best to enclose them in single quotes to stop the shell from expanding it before passing it to grep or other tools. David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 6
Regular Expression Notes: Regular Expressions are used all over the place. We’ve already seen grep , which takes RegExp search strings. Later we’ll see some other fun commands which will use them.
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern