CS701 : Software Practice and Experience
Laboratory 2004-2005
Quiz 3
Topic : Shell Programming
Date : October 26, 2004, 2:00pm to 4:00pm.
Some Reference Manual Links
- Basic Commands: wc, grep, sed, head, tail,
find, sort, cut, who, finger, ps, kill
- Bash
Reference Manual
- GNU
Make
- How to
Write a Shell Script
- Shell
programming
- Advanced
Bash-Scripting Guide
General Instructions
- Sit only at the place assigned to you. Do not access any other
system.
- You can use internet, shell-programming documentation, tutorials
and your own assignment code.
- Accessing email, messages or any other personal
communication (including phones) are not allowed during examination
hours.
- Sharing files is strictly prohibited.
- There will be no extension of time. The upload form will be
closed at 4:00pm.
- There will be PENALTY for late and incorrect submissions.
- Quiz evaluation will be from 4:15pm-5:30pm.
NOTE
: If no argument is provided then script should print the usage.
Question 1
6 Marks
Write a script "random <filename>" to select a random line from
given text file.
Hint : expr $RANDOM % 10
prints random number between 0 and 9.
Sample input file
Question 2
12 Marks
PATH variable contains number of ":" separated directories.
Write a script for following without
using 'find' command.
a) "list -e <extension>" which prints all files having
given extension in directories of PATH variable.
b) "list -s <size>" which prints all filenames in directories of PATH variable with
size greater than input size.
In both the options, you need to print absolute path.
You don't have to handle both options at same time.
Hint: Parse the PATH and do it for each directory.
Following commands create a bin directory in home directory and adds
some files in it.
mkdir -p ~/bin
PATH=$PATH:~/bin
touch ~/bin/yogesh.java ~/bin/sandeep.ksh ~/bin/sachin.sh
~/bin/tarun.java ~/bin/babu.tex ~/bin/vats.pl
Question 3
12 Marks
File Records.txt contains the set of entries
in following format :
TITLE: XXXXXXXXXXXXXXXXXXXXX
<Multi line description>
<single line summary>
Each Title can be assumed to be unique.
Two entries are separated by a blank line.
Write the following scripts without
using 'awk' command.
a. "getEntry <n:Entry number> <filename>" which prints the nth
entry in the file.
b. "getSummary <Title> <filename>" which prints the summary
for the given title.
Note: Title being a string needs to be enclosed in double quotes.
Hint: for ((I=0;I<10;I++)); do
echo "Lopping $I"; done prints numbers from 0 to 9.
Submission Guidelines
- Submission through upload form.
- Only one submission allowed per person.
- Final submission will be <rollno>.tgz which will
explode into <rollno> directory containing four shell scripts
random, list, getEntry and getSummary.