You are on page 1of 3

Jaypee Institute of Information Technology, Noida

Assignment 6 (Week: Oct 6- 11, 2014)

Sub Name: Unix Programming Lab


Topic: Practice Questions on Shell Scipt

Sub Code: 10B17CI307


Marks: 10

Instructions:
1. Attendance should be 80 %, otherwise you may be debarred from the lab.
2. Notesprovidedaremeantonlyforguidelines.Notessolelywillnotcoverthesyllabus.Read
prescribedbooks.

Note: Lab Test1 (20 Marks) is scheduled in week 13-18 Oct for all the batches. Syllabus
is shell scripting. Absence from Lab Test 1 will lead to 0 marks.
Refer the all the notes from Lab1 to Lab 6 and Chapter 14 & 15 of the book UNIX:
Concepts and Applications, Das, Sumitabha, Tata McGraw-Hill, Third Edition
Question 1 Develop an interactive script that
a) asks for a word and a file name and then tells how many times that word occurred in
the file.
b) perform the following string operations: (substring and string should be taken as
command line argument.)
i) To extract a sub-string from a given string.
ii) To find the length of a given string.
c) offers the user the choice of copying, removing, renaming, or linking files. Once the
user has made a choice, have the program ask the user for the necessary information,
such as the file name, new name and so on
Question 2 Write a shell script that
a) accepts a file name starting and ending line numbers as arguments and displays all the
lines between the given line numbers.
b) deletes all lines containing a specified word in one or more files supplied as
arguments to it.
c) receives two file names as arguments. It should check whether the two file contents are
same or not. If they are same then second file should be deleted
Question 3 (i) Write a script index.sh which will be invoked with a single parameter that
specifies the data file to be used.
$ ./index.sh data.txt
After removing all punctuation and tabbing characters from the data file, and making
every upper-case letter lower-case, the script should output all remaining words to
freq.txt in decreasing order of frequency. Each line should consist of two columns
separated by a tab: the number of occurrences, followed by the word itself.

For example content of freq.txt must be like


12
quality
10
scrabble
2
scoring
1
highest
1
word
Question 3 (i ) Generated freq.txt file from running index.sh. Now update the index in
freq.txt for a new document.
For instance, if we use the index from the earlier example and new.txt contains:
The highest scoring word in Scrabble is QUALITY.
Then the updated index should read following by using freq.txt and new.txt.
13
11
3
2
2
1
1

quality
scrabble
scoring
highest
word
in
is
1

the

Question 4 Mr X and Ms Y are brilliant students. T, their teacher asked them to code 5
programs (1.c, 2.c, 3.c, 4.c and 5.c). Their programs are present in directories progs/X
and progs/Y respectively. Due to time constraint they may have not submitted some
programs.
a) Create this sample data in your directories. Create program files also, by entering
dummy data. No created file should be empty.
b) Write a shell script that accepts a student name as program argument and gives
his/her total marks.
Question 5 .The information about the employee is stored in a file called employee.txt as
a record consisting of the emp_id ,emp_name , Department ,Salary.
Write a script in which file name along with the option is to be passed through command
prompt .
Depending upon the options the shell script should do following tasks :
Option 1) Display the names of all the employees with name not starting from a or b or A
or B.
Option 2) Display record of all the employees whose salary is between 7000 to 8000.
Option 3) display all the employees in account department.

Question 6. Create a scripts srm.sh that moves the files to the specified directory, instead
of removing files. Script srm.sh should check whether the directory is present or not, if
not then create a directory trashcan. The script will assign a new name to the files while
in the directory. Lets say you perform the following command
$. /srm myfile
This command will move myfile (it will no longer exist in the original location) and will
create myfile-MMDDYYYY where MM is month, DD is day and YYYY is year in 4
digit format under $students/xyz/trashcan.

You might also like