Lecture 3 - 1/23/11 ECE 364: Software Tools Laboratory...

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

View Full Document Right Arrow Icon
1/23/11 1 ECE 364: Software Tools Laboratory Lecture 3 January 24, 2010 Lecturer: Michael Goldfarb 1 Lecture Outline § Case Statement § Sort Command § Internal Field Separator (IFS) § KornShell strings and patterns § Awk and Sed in 60 sec, EEEK! § Argument processing with getopts § Menus 2
Background image of page 1

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

View Full DocumentRight Arrow Icon
1/23/11 2 Case Statement § The case statement is similar to the switch statement in C § Much more powerful in KornShell, can use patters to handle each case case <var> in <pattern1>) …commands… ;; <patternN>) …commands… ;; esac 3 Case Statement (2) § Put a “ * ” as the last pattern as the catch all or default case. § See later slides for coverage of KSH patterns case ${answer} in [Yy]) print “You said Yes!” ;; [Nn]) print “You said No!” ;; *) print “Error: Y or N.” ;; esac 4
Background image of page 2
1/23/11 3 sort Command § The sort command sorts data in a file § Can sort entire tables not just a single values § Lots of possibilities so read the man page § Common Options: -u unique lines only -tx field separator x (default is whitespace) -b ignore leading blanks -r reverse sort -n treat characters as numbers -k sort on fields 5 sort Command (2) § Consider a file called “sortme” that contains: 555 Mike Goldfarb mgoldfar 666 Jacob Wyant jwyant 777 Jung Yang yang205 444 Aarthi Balachander abalacha § To sort by TA name (2nd column): $ sort –k2 sortme 444 Aarthi Balachander abalacha 666 Jacob Wyant jwyant 777 Jung Yang yang205 555 Mike Goldfarb mgoldfar 6
Background image of page 3

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

View Full DocumentRight Arrow Icon
1/23/11 4 sort Command (3) § Consider a file called “sortme2” that contains: ece 201 fff aaa 100 fff bbb 199 ggg ccc 302 fff § To sort on column 3 first and then on column 2: $ sort –k3 –k2 sortme2 aaa 100 fff ece 201 fff ccc 302 fff bbb 199 ggg 7 Internal Field Separator (IFS) § Anything that looks like list separated by whitespace is actually separated by the special internal field separator. § The IFS is a variable that you can change § By default the IFS is set to whitespace § Space, tab, and newline 8
Background image of page 4
1/23/11 5 Internal Field Separator (2) § To set using double quotes: IFS=“.:” § To set using single quotes: IFS=$’ \t\n:’ 9 Internal Field Separator (3) § Consider a file called “dotdata” that contains: 12.45.63.56 24.24.32.12 31.32.14.64 § Changing the IFS lets us process the contents of each line in different ways § Treat each line as a single string § Or treat each line as a list of numbers separated by a period 10
Background image of page 5

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

View Full DocumentRight Arrow Icon
1/23/11 6 Internal Field Separator (4) IFS=$’\t\n ’ while read line do for num in $line do print –n \”$num\” done done < dotdata Prints each number on its own: “12.45.63.56” “24.24.32.12” “31.32.14.64” 11 Internal Field Separator (5) IFS=“.” while read line do for num in $line do print –n \”$num\” done done < dotdata Prints each number on its own: “12” “45” “63” “56” “24” “24” “32” “12” “31” “32” “14” “64” 12
Background image of page 6
1/23/11 7 Internal Field Separator (6) § Recall the predefined variables
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 note was uploaded on 04/26/2011 for the course ECE 364 taught by Professor Niklaselmqvist during the Fall '10 term at Purdue University-West Lafayette.

Page1 / 21

Lecture 3 - 1/23/11 ECE 364: Software Tools Laboratory...

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