Lec4Handouts

Lec4Handouts - CS2044 Advanced Unix Tools Spring 2009...

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

View Full Document Right Arrow Icon
CS2044 - Advanced Unix Tools Spring 2009 Lecture 4 David Slater dms236 at cornell.edu February 23, 2009 David Slater dms236 at cornell.edu CS2044 - Advanced 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 Minor typo in hw1 fixed. Homework 1 due Friday at 6 pm. I am amazed how many of you uploaded scripts for the questionnaire that did not run :( David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 2
Some Review What does this do? gawk ’BEGIN { max = 0 } { if (length($0) > max); max = length($0) } END { print max } ’ infile David Slater dms236 at cornell.edu CS2044 - Advanced 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? gawk ’BEGIN { max = 0 } { if (length($0) > max); max = length($0) } END { print max } ’ infile Prints the length of the longest line gawk ’END { print NR } ’ infile David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 4
Some Review What does this do? gawk ’BEGIN { max = 0 } { if (length($0) > max); max = length($0) } END { print max } ’ infile Prints the length of the longest line gawk ’END { print NR } ’ infile Prints how many lines are in the file #! /bin/bash gawk ’$1 = "’$1’" { count++ ; print $2 } END { print count } ’ infile David Slater dms236 at cornell.edu CS2044 - Advanced 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
Some Review What does this do? gawk ’BEGIN { max = 0 } { if (length($0) > max); max = length($0) } END { print max } ’ infile Prints the length of the longest line gawk ’END { print NR } ’ infile Prints how many lines are in the file #! /bin/bash gawk ’$1 = "’$1’" { count++ ; print $2 } END { print count } ’ infile Prints the second field whenever the first matches the first argument and then prints the total number of matched lines. David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 6
Passing arguments to scripts When we pass arguments to a bash script, we can access them in a very simple way: $1, $2, . .. $10, $11 - are the values of the first, second etc arguments $0 - The name of the script $# - The number of arguments $* - All the arguments, ”$*” expands to ”$1 $2 . .. $n”,
Background image of page 7

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

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

This document was uploaded on 05/21/2009.

Page1 / 29

Lec4Handouts - CS2044 Advanced Unix Tools Spring 2009...

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

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