cs2042_Lecture7 - CS2042 - Unix Tools Fall 2009 Lecture 7...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

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

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

View Full DocumentRight Arrow Icon
Organization Homework 2 Due Tonight! Homework 3 passed out today, due Monday October 19th at 11:59PM. David Slater dms236 at cornell.edu CS2042 - Unix Tools
Background image of page 2
Some Review What does this do? sed ’s/^[ \t]*//g’ myfile David Slater dms236 at cornell.edu CS2042 - Unix Tools
Background image of page 3

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

View Full DocumentRight Arrow Icon
Some Review What does this do? sed ’s/^[ \t]*//g’ myfile Removes all leading whitespace sed ’/^#/d’ /etc/services | more sed ’/^[^#]/d’ /etc/services | more David Slater dms236 at cornell.edu CS2042 - Unix Tools
Background image of page 4
Some Review What does this do? sed ’s/^[ \t]*//g’ myfile Removes all leading whitespace sed ’/^#/d’ /etc/services | more sed ’/^[^#]/d’ /etc/services | more The first displays the file without comments, the second displays only the comments David Slater dms236 at cornell.edu CS2042 - Unix Tools
Background image of page 5

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

View Full DocumentRight Arrow Icon
Do you grok gawk? gawk gawk is a small pattern matching programing language. The basic structure of an gawk program is pattern1 { commands } pattern2 { commands } . . . patterns can be regular expressions! Gawk goes line by line, checking each pattern one by one and if its found, it performs the command. David Slater dms236 at cornell.edu CS2042 - Unix Tools
Background image of page 6
awk introduction awk ’s purpose: A general purpose programming filter that handles text (strings) as easily as numbers This makes awk one of the most powerful of the Unix utilities awk processes fields while sed only processes lines. nawk is the new standard for awk and gawk is a free clone from GNU awk gets input from files redirection and pipes directly from standard input David Slater dms236 at cornell.edu CS2042 - Unix Tools
Background image of page 7

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

View Full DocumentRight Arrow Icon
gawk highlights A programming language for handling common data manipulation tasks with only a few lines of code A pattern-action language, like sed Looks like C but automatically handles input, field splitting, initialization and memory management Great for database files (essentially large tables) Great prototyping language (i.e. start with a few lines and keep adding until it does what you want David Slater dms236 at cornell.edu CS2042 - Unix Tools
Background image of page 8
Why awk and not sed Convenient numerical processing Variables and control flow in the actions Convenient way of accessing fields within lines flexible printing built-in arithmetic and string functions David Slater dms236 at cornell.edu CS2042 - Unix Tools
Background image of page 9

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

View Full DocumentRight Arrow Icon
Simple Examples gawk ’/[Mm]onster/ { print } ’ Frankenstein.txt gawk ’/[Mm]onster/’ Frankenstein.txt
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/15/2010 for the course CS 2024 taught by Professor Dinapoli during the Fall '07 term at Cornell University (Engineering School).

Page1 / 33

cs2042_Lecture7 - CS2042 - Unix Tools Fall 2009 Lecture 7...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online