CS 279 - Week 10 Lecture 2 - 10-25-12

*   a few more words on ls:
---------------------------
    -R - list subdirectories recursively.

    -F - indicates file type in its output --
         puts * after an executable file,
	 put / after a directory,
	 put @ after a symbolic link.
    
    -t - lists the files in chronological order,
         by default, in order of last modification,
	 newest first.

         -tr gives you the OLDEST files first.

         -tu gives you the files in order of last ACCESS
	 newest first.

    -u - with -l uses ACCESS time (shows that instead
         of last-modified time).

    -c - with -l uses when the i-node was last modified
         "namely, when the file was created or its 
	 permissions last modified".

head (section 4.4.1, p. 184)
tail (section 4.4.2, pp. 184-186)
---------------------------------
*   head [-n num] [files ...]

    *   if no -n option, displays the first 10 lines
        of the indicated files.
    *   if no files, it takes input from standard
        input (so it can be used in a pipe).
    *   if -n and a number, it displays
        the first that-many lines.

tail 
----
*   tail displays parts from the end of a file.
    
    tail [-f] [-c num | -n num] [file]

    *  if NO -c or -n, the last 10 lines are displayed
       (default).

    *   if -c num, the last num BYTES are displayed.
    *   if -n num, the last num LINES are displayed.

    *   if you put a + in front of the num for -c or -n,
        it displays starting at the numth byte or line
	    in the file.

        if no sign or a - in front of the number,
	it's the "typical" behavior noted above.

*   -f option - doesn't terminate after producing its
    output. Instead, it awaits further bytes from
    its input file, and shows them if they become available.

    only way to stop it is to interrupt it or to
    kill its parent process.

    (with a pipe and standard input, the tail -f
    DOES terminate when the pipe terminates.)

intro to sed
------------
*   stream editor?
    can be used for modifying streams of text on the fly
    originally written in 1973 or 1974 by Lee E. McMahon.

    derived from the ed editor, although it is NOT
    just like it.

*   the BASIC work cycle of sed:
    1. reads a line from standard input into its
       pattern buffer (text calls this the input
       buffer).
    2. modify the pattern buffer according to
       the supplied commands.
    3. print the pattern buffer to standard out.

*   an application of sed consists of applying
    a fixed editing script to a sequence of files.

    sed [-n] script [file..]
    sed [-n] [-e script] ... [-f scriptfile] [file..]

*   an editing script consists of a sequence of commands
    separated by either newlines or semicolons.
    *   each command is indicated by a single letter or other
        character.
    *   most commands can be preceded by a selector,
        either an "address" or a pair of "addresses"
	called a range.

    *   if there's a selector, only the lines selected
        by that selector have the commands done to them.

    *   "address" means either a line number
         or a basic regular expression.

         range can be two "addresses" separated by a 
	 comma, do the action JUST to the lines in
	 that range (inclusive).

*   one quick command to start:
    s for substitute

    [selector] s/patt/repl/[flags]

    example flag: g, means replace EVERY instance
    of patt with repl in the line(s) indicated by
    selector, OR all lines if no selector given.

    no flags? replaces the FIRST instance in each line.

    a flag that's an int num? replaced the numth instance in
    each line.

(more on sed on Tuesday)