FIRST UNIX SESSION ssh cs313@wolf.cs.wustl.edu w who whoami top (CTRL-C) df pwd ls ls -1 | wc ls -lt | head -10 ls -lt | head -10 | wc ls -lt | tail -10 | wc ls | less (SPACE, ENTER, j, k, q) ls -s ls -l du clear exit SECOND UNIX SESSION ssh cs313@wolf.cs.wustl.edu mkdir loui04 cd loui04 find .. -name words find .. -name words | gawk '{system("cp "$1" words"++n)}' ls ls -s diff words3 words4 less words3 (/ate, /ate$) grep 'ate$' words3 grep 'ate$' words3 > words5 vi words5 (:g/./ s/ate$/ated, :wq) REVIEW REGEXPS . .* [a-z]* [^a-z] ^ $ [0-9]+ ^ [1-9]\. [1-9][0-9]*\.?[0-9]* [aeiou][^aeiou][aeiou] <[^>]*> vi insulter0.awk (i, ESC, :wq) BEGIN { while (getline < "words5") w[n++] = $1 while (1) { print "You are so damned "w[int(rand()*n)]"." getline # your turn } } gawk -f insulter0.awk (CTRL-C) vi insulter0.awk (/while, O, ESC, :wq) srand() vi insulter0.awk (O, ESC, :wq) #! /bin/gawk -f chmod a+rx insulter0.awk ls -l insulter0.awk ./insulter0.awk cp words4 words5 alias cp alias cp 'cp -i' !grep echo > words5 !grep ^words5^words4 !!:s/words4/words5 history top (CTRL-Z) jobs kill -9 25327 top (CTRL-Z) fg (CTRL-C) cd ~ ls -a spell.awk BEGIN { while (getline < "words") w[$1] = 1 } { for (i=1; i<=NF; i++) if (!w[$i]) print $i " is misspelled!" } or BEGIN { while (getline < "words") w[$1] = 1 } { for (i=1; i<=NF; i++) if (!w[$i]) print $i " is misspelled!" } GAWK HIGHLIGHTS autotyping of variables (is this a string context or numeric?) autoinitialization (if string, then "", if numeric, then 0) implicit operation on lines {}, preceded by BEGIN{} section automatic parsing of input into $1, $2, ... using field separator FS file and pipe handles are strings there is no concatenation operator arrays are all associative, and all indexed by strings, automanaged statements or statement blocks {} semi-colon is optional, and used to group multiple statements on a line # produces a comment to the end of the line man gawk is a good read FIRST DAY WITH VI ESC puts you in command-mode (if you happen to be in insert-mode) :vi puts you in visual-mode (if you happen to be in colon-mode) VI is based on a COMMAND GRAMMAR :w writes the file :w! writes the file, over an existing file :q quits :q! quits, discarding changes :wq writes and quits :wq! writes and quits, over an existing file :w fn writes the file as fn :w! fn overwrites the file as fn :n edits the next file (e.g. % vi foo* ) :g/bah/ s/foo/bar goes to every line matching bah substitutes first foo with bar COMMANDS ENTERING INSERT-MODE a append after current char i insert before current char A append after current line I insert before current line s substitute this character c$ change from here to end of line c0 change from here to beginning of line cw change this word c3w change the next three words cfn change from here until you find an n, including the n ctn change from here until you find an n, excluding the n c3fn change from here until you find the third n, including c3tn change from here until you find the third n, excluding o open a line below this line O open a line above this line COMMAND TO EXIT INSERT-MODE ESC COMMANDS THAT CHANGE CHARACTERS r replaces this character for the next one typed R replaces characters until ESC BASIC MOTION 0 move to first character on line $ move to last character on line w move forward a word b move back a word e move to end of word h,j,k,l left,down,up,right - up ENTER down G go to last line 1G go to first line 11| go to 11th column fn find an n in the line tn find before an n in the line ; repeat f or t command /fooENTER find next occurrence of foo (across lines) ? reverse / command ?fooENTER find previous occurrence of foo (across lines) n repeat / or ? command