For each of the following problems, I'd like to see not only the
command or alias you came up with, but also one or more tests. To show
me your tests, I suggest starting a shell session whose output goes to
both the screen and a file (tcsh | tee logfile
), typing
the various commands you want to demonstrate, then exit
and
e-mail me the log file.
Imagine that you're writing a big C program, and you have a bunch of
source files (whose names end in .c
) and a bunch of include
files (whose names end in .h
), all scattered around a
project directory and its subdirectories.
Write a Unix command to list all the files in a specified
file hierarchy whose names end in .c
or .h
.
Write a csh
alias for this
command. It should take in the directory as its first and only
parameter.
Imagine that in this big C program is a function named
snark
, which you've decided to rename as
boojum
.
Write a Unix command to edit (using vi)
all the files in a specified file hierarchy whose names end in
.c
or .h
and whose contents contain the name
snark
. (Hint: first figure out a Unix
command to simply list the pathnames of the relevant files.)
Write a csh
alias for this command.
It should take in the directory name as its first parameter, and the
name of the function you're looking for (snark
in the above
example) as its second parameter.
Write a Unix command to show all the lines in a
specified file that do not contain the string
"-option"
.
(This can be done either with sed or with grep.
Try both approaches.)
Write an alias named freq for a pipe
which reads words from stdin
, counts how often each one
occurs, and produces output in which each line is a word followed by how
many times it occurred in the input. The lines of output should be
sorted in decreasing order of frequency. (You should be able to do this
using only standard Unix commands, not writing any C or C++ code.)
Hint:
It may be easier to do this as a shell script, rather than an alias for
a pipe. You can do it as a shell script using fairly simple filters;
you can do it as a single pipe using awk
.
For those of you who have taken Dr. Siegfried's courses, another name
for this might be "concordance"....