Week 6 - Graded+Practice Assignment
Week 6 - Graded+Practice Assignment
Problem 1
file1.txt is a file containing some text . The command awk '{print}' file1.txt is equivalent to which
of the following commands, irrespective of the data in file1.txt . [MSQ]
Answer
(1), (2) and (4)
Problem 2
What is the output of the below command?
[MCQ]
(1) 45
(2) 204
(3) 37
(4) 285
Answer
(4) 285
Problem 3
What is the output of the following bash script?
Note that before executing the below script the file numbers.txt is empty. [MCQ]
for i in {1..10}; do
for j in {1..10}; do
echo $i, $j >> numbers.txt
done
done
(1) 3025
(2) 2025
(3) 45
(4) 55
Answer
(1) 3025
Problem 4
In which of the following commands output, the 1st and 2nd column of input will be inverted? In the input,
the 1st and 2nd columns are separated by a comma, and in the output too the columns should be
separated by a comma.[MSQ]
Answer
(3)
Problem 5
The purpose of the following command is to
(1) Calculate the number of characters in all the files in the current directory.
(2) Calculate the space occupied by all the files in the current directory in bytes.
(3) Calculate the sum of creation dates of all the files in the current directory.
(4) Calculate the number of lines in all the files in the current directory.
Answer
(2)
Problem 6
$ cat employee_details.txt
A1998001,Ram Kumar,10,Male
B2000002,Sanjay Narayan,7,Male
B2000003,Srishti Rai,10,Female
E1997001,Manoj Pillai,12,Male
G1998001,Preeti Suresh,9,Female
G1999001,Leela L G,16,Female
[MCQ]
(1)
3 B2000003
5 G1998001
(2)
3 B2000003,Srishti Rai,10,Female
5 G1998001,Preeti Suresh,9,Female
(3)
3 B2000003
4 E1997001
5 G1998001
(4)
3 B2000003,Srishti
4 E1997001,Manoj
5 G1998001,Preeti
Answer
(4)
Problem 7
Which of the following commands can be used to calculate the number of lines in the file
employee_details.txt . [MSQ]
(1)
(2)
(3)
(4)
Problem 8
$ echo To be or not to be | tr " " "\n"
Which of the following awk commands will give same output as the command above? (MCQ)
Note: tr " " "\n" will replace each space by a newline character. i.e. each word in the string "To be or not
to be" will be printed on a new line by the command echo To be or not to be | tr " " "\n"
(1)
(2)
(3)
(4)
Answer
(2)
Problem 9
Match the following expr operators to their use.
Operator Use
1. index str1
A. Returns the substring y characters in length starting at position x.
str2
2. substr str x y B. Returns the pattern match if 'str1' matches the pattern in 'str2'
3. match str1
C. Returns the substring 'x' characters in length starting at position 'y'.
str2
E. Returns the starting position of substring 'str2' if found in the string 'str1'; else
return 0
F. Returns position in 'str1' if any of the characters given in 'str2' is found; else
return 0
Answer
(4)
Problem 10
Which of the following scripts will give the output as below.[MSQ]
2,10
4,20
6,30
8,40
10,50
(1)
(2)
for (( i=2,j=10; i<11; i+=2,j+=10)); do
echo $i,$j
done
(3)
(4)
(5)
Answer
(2) and (5)
Week 6 - Practice Assignmet
Problem 1
What will be the format of the output of the following command? [MCQ]
Answer
(3) File Permission, File Name
Problem 2
Which of the following commands will print the file, appending the line number to the starting of each line,
irrespective of the data in the file? [MSQ]
(1)
(2)
(3)
Answer
(3)
Problem 3
What is the output of the command given below? (MCQ)
(1)
3
Error
(2)
4
Error
(3)
3
0
(4)
4
0
Answer
(3)
Problem 4
The built in variable NF used in awk scripts is used to.
Problem 5
What is the output of the following command? (MCQ)
Answer
(4)
##