Lecture 2
Stderr
Where we expect error messages
Unbuffered stream (information is printed immediately)
Make sure error message doesn't get mixed up with output
To redirect:
How many words occurs in first 20 lines of file.txt?
Pipeline
Suppose words.txt, words2.txt, etc. each contains a list of words, one per line. Produce a duplicate-free list of all words that occur.
$ sort
$ sort
sorts lines in lexicographical order
$ uniq
$ uniq
removes adjacent duplicate lines
-c counts occurrences adjacent lines
Can we use output from a program as an argument to another program?
files.txt contains a list of files on one line
We want to use that list of files as arguments to a program
Embedded Command
How to find words or patterns in a file
$ egrep
$ egrep
extended global regular express print
More Pattern Rules
(pattern) groups contents together
[chars] match one instance of any character
eg.
[a-z]
matches any of a-zdon't do
[A-z]
to get all of alphabet (looks for ASCII between capital letters and lowercase letters)
[^chars] matches anything except these characters
? : previous pattern occurs 0 or 1 times
eg.
[Cc][Ss] ?246
(don't know if ppl do CS246 or CS 246)
* : 0 or more occurrences of preceeding pattern
(cs)*246 matches: 246, cs246, cscs246, cscscs246, etc.
+ : 1 or more occurrences of preceeding patern
. : match one instance of any character
.* : match 0 or more instances of ny char
^ : matches beginning of line
eg.
^cs246
(must begin with cs246)
$ : matches end of line
eg.
cs246$
(must end with cs246)
Example: Find lines of even length
ls -l
ls -l
Shows "long" form of files
Last updated