USP LabSetQuestions-Final
USP LabSetQuestions-Final
(An autonomous institution affiliated to VTU, Belagavi, Approved by AICTE, New Delhi,
Accredited by NAAC with 'A' grade & ISO 9001:2015 Certified)
Department of Computer Science & Engineering
(Program Accredited by NBA)
Lab 1:
1. How do you achieve the following using basic unix commands and vi editor:
i) create a file, identify its attributes vi filename,ls -l
ii) edit the file contents using vi editor: insert-lines, words, copy-lines,
words, delete-lines words, cut-lines words, append, search, navigating
across the file chmod 777 filename
iii) change the permissions of the files – both octal and symbolic notations
iv) create a new user and change the ownership of the file sudo useradd username
chown username filename
v) record your login session script
vi) change any 3 terminal characteristics stty -a $stty eof ^k
vii) create a directory structure, remove the current working directory and
navigate across the file system – absolute and relative paths
viii) create hard link and symbolic link for a file and identify the same in
the file system ln source destination
2. Create a database file using space as a delimiter. How do you achieve the following?
i) Display first 6 lines of the file
ii) Display last 6 lines of the file
iii) Display lines from 5 to 8 of the file head -8 database.txt | tail -4
iv) Display specified columns from a file cut -c 6-13,19-24 database.txt
v) Combine two files vertically cat m1.txt m2.txt >merge.txt
vi) Sort the file based on field attributes sort -k2 file.txt
vii) Search a given file find -name database.txt -print
viii) Count the number of characters, words and lines in a file wc database.txt
Lab 3:
3. Given a file
i) Redirect the file contents to both terminal and a new file
ii) Enter a wrong command and redirect the error to a error file
iii) Rectify the command and append the output to the same error file
iv) Execute, cat file1.c nofile , Redirect the output of successful command to a
file and error to error file
v) Given two files, compare them using different filters
vi) Redirect the output of a command to /dev/null . What is your observation?
vii) Search a file based on a criteria
viii) Identify suitable command for input redirection
Lab 4:
4. Create a text file, How do you achieve the following using GREP:
i) Remove the blank lines from the file grep . hello.txt
iii) Select lines that have exactly 5 characters grep '^.....$' hello.txt
iv) Select the lines with leading or trailing zeros grep -E '*0','0*' hello.txt
v) Number the above lines of text grep -n '^.*$' hello.txt
vi) Select lines that do not start with A to K. grep '^[a-k].*$' hello.txt
5. Create a text file, how do you achieve the following using sed
i. Replace all Read with Retrieve sed 's/read/retrieve/g' hello.txt
ii. Delete the blank line that follows the line that starts with an alphabet. sed '/^$/d'
hello.txt
iii. Double space the file sed 'G' hello.txt
iv. Extract the first word of each line sed 's/ .*//' hello.txt
v. Extract the year from the date in mm/dd/yyyy format sed -n 's/..\/..\/\(....\)/\1/p' hello.txt
vi. Print the line following a pattern match
vii. Merge the odd numbered line and even numbered line. Eg. Merge 1st and
2nd line, 3rd and 4th line , ………………
viii. Delete any integer in each line. sed 's/[0-9]//g' hello.txt
ix. Insert header info “ Summary sheet” available in the file new.txt
x. Simulate copy, head and tail sed -n 'p' hello.txt>new.txt
Lab 6:
Lab 8:
Write a shell script that accepts a list of filename as its arguments counts and reports the
occurrence of each word that is present in the first argument file on other argument files.
Lab 9:
Implement menu driven program to do arithmetic calculator operation by reading inputs from
a function
Lab 10:
Write a shell script to check the permission of a file, print filename along with line numbers
and copy the contents of files to another file.