CS/CE 218 Lecture -*-Outline-*- note: I added more examples of regular expressions that weren't covered in class; these would have really helped... connection: still continuing our discussion of manipulating text (e.g. programs) under program control; we've seen the shape of a standard Unix comamnd, and how to hook commands together into pipelines; we've also seen how to control commands and pipelines that take a long time to finish. We saw that the most important command for pipelining was a filter. Today we'll look at filters that work on (ascii) text files; these are all ways to "observe" a file. * text-manipulation advert: allow to to treat your program source files as a database, to make major changes quickly, to get "into" the files and look at them in unplanned ways examples of sort, wc, grep, tr, sed, cut, paste, diff, ... ** wc (word count) section 6.4 counts lines, words, and characters in a document Q: How would you tell how many lines are in gigantic.c using wc? wc -l gigantic.c or wc -l names" and "cut -f2 id-index >lines", how do you use paste to put id-index back together? How do use use pr to do it? paste names lines pr -t -m -w10 names lines *** diff (comparing files) section 6.12 diff finds the smallest set of differences between 2 files Q: If you have two files, f.c and f.c~, what does "echo f.c*" print? f.c, then f.c~ so diff f.c* gives f.c as 1st arg, f.c~ (old) as 2nd. Q: Does diff check to see which file is older? contrary to book no, just uses order. 1st arg | 2nd arg < | > ------------------ $ diff .profile* 14a15,18 > ENV="$HOME/.kshrc" > . "$ENV" > export ENV > 29,36c33 < # set path variables < . "$HOME/.path.sh" < < ENV="$HOME/.kshrc" < . "$ENV" < export ENV < < . "$HOME/.startup.tty" --- > . $HOME/.startup.tty -------------------- first arg is .profile~ (the old file) so I moved the ENV lines from after . $HOME/.path.sh to before that (after line 14 in the old file) *** sdiff and comm sdiff would be useful if displays were wider; shows differences side by side, useful for merging variants comm is the opposite of diff in a sense, but also shows differences output may be confusing if files have initial tabs