- Delete the blank lines in the file.
sed '/^$/d' faculty.details
- Print the lines pertaining to faculty who have offices in Torgersen Hall.
sed -n '/Torgersen Hall/p' faculty.details
- Find the line numbers describing faculty who teach undergraduate courses.
sed -n '/CS [1234][0-9][0-9][0-9]/=' faculty.details
- You are given that Heath, Kafura are full professors. Ramakrishnan
is an associate professor. All others are assistant professors. Print
each professor's designation on a separate line, after the given line,
in the form "Designation: ".
/Heath/ {
a\
Designation: Full Professor
p
b
}
/Kafura/ {
a\
Designation: Full Professor
p
b
}
/Rama/ {
a\
Designation: Associate Professor
p
b
}
{
a\
Designation: Assistant Professor
p
}
(put the above in a file, say designation.f and invoke it
as: sed -f designation.f faculty.details) Note that the
"b" commands are important, otherwise since the last command
is supposed to work for all lines (note the lack of addresses),
everybody will also be listed as an assistant professor. Also note that
you can append multiple lines, each must be followed by a "\" except
the last line (observe the "\" after the a command). The
braces "{" and "}" must be where they are, i.e., the "{" must end the
first line and the "}" must be on a line by itself.
- Print the lines in the format 'name:office:course' i.e., strip the headers "Name:" and "Office:" and "Course:".
sed 's/Name: \(.*\) Office: \(.*\) Course: \(.*\)/\1:\2:\3/' faculty.details
- Print the lines in the format 'course:office:name'.
sed 's/Name: \(.*\) Office: \(.*\) Course: \(.*\)/\3:\2:\1/' faculty.details
- Break down every entry onto three lines.
sed 's/Name: \(.*\) Office: \(.*\) Course: \(.*\)/\1\n\2\n\3/' faculty.details