Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

Linux MCQ Set 1

1. What is expression in awk programming?
a) expression evaluates a value to print, test or pass to a function
b) expression assigns a new value to a variable or field
c) expression evaluates a value to print, test or pass to a function & also assigns a new value to a variable or field
d) none of the mentioned

View Answer

Answer: c [Reason:] None.

2. Which one of the following is not true?
a) there are 3 types of constant expressions: numeric, string and regular
b) arithmetic operators are used to evaluate expressions
c) assignment expression is an expression that stores a value into a variable
d) comparison expressions does not compare strings for relationship

View Answer

Answer: d [Reason:] None.

3. All numeric values are represented within awk in
a) double precision floating point
b) integer
c) exponential notation
d) fixed point

View Answer

Answer: a [Reason:] None.

4. Concatenation is performed by
a) writing expressions next to one another, with no operator
b) conditional operator
c) relational operator
d) matching operator

View Answer

Answer: a [Reason:] None.

5. The comparison expression “x ~ y” will true if
a) x is not equal to y
b) the string x does not match the regular expression denoted by y
c) the string x matches the regular expression denoted by y
d) none of the mentioned

View Answer

Answer: c [Reason:] None.

6. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        print "20"<"9" ? "true":"false"	      
  4.    }

a) true
b) false
c) syntax error
d) none of the mentioned

View Answer

Answer: a [Reason:] The operands of relational operators are converted to, and compared as string if both are not numbers. Strings are compared by comparing the characters of each. Hence 20 is less then 9. Output: :/home/aidlo# chmod +x test.awk :/home/aidlo# ./test.awk true :/home/aidlo#

7. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a=10;
  4.        b=10;
  5.        print a==b ? "true":"false"	      
  6.    }

a) true
b) false
c) syntax error
d) none of the mentioned

View Answer

Answer: a [Reason:] None. Output: :/home/aidlo# chmod +x test.awk :/home/aidlo# ./test.awk true :/home/aidlo#

8. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        var1="aidlo"
  4.        var2="linux"
  5.        print var1" provides "var2" MCQs "	      
  6.    }

a) aidlo provides linux MCQs
b) var1 provides var2 MCQs
c) provides MCQs
d) syntax error

View Answer

Answer: a [Reason:] None. Output: :/home/aidlo# chmod +x test.awk :/home/aidlo# ./test.awk aidlo provides linux MCQs :/home/aidlo#

9. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        two=2;
  4.        two++;
  5.        print two 
  6.    }

a) two
b) three
c) 2
d) 3

View Answer

Answer: d [Reason:] None. Output: :/home/aidlo# chmod +x test.awk :/home/aidlo# ./test.awk 3 :/home/aidlo#

10. What is the output of this program?

  1.     #! /usr/bin/awk -f
  2.     BEGIN {
  3.         one=10;
  4.         two=3;
  5.         print (one%two)+10 
  6.     }

a) (one%two)+10
b) 13
c) 11
d) syntax error

View Answer

Answer: c [Reason:] The remainder of 10/3 is 1. remainder is added to 10. Output: :/home/aidlo# chmod +x test.awk :/home/aidlo# ./test.awk 11 :/home/aidlo#

Linux MCQ Set 2

1. Which one of the following is not true?
a) nawk is the new version of awk
b) gawk is the GNU version of awk
c) linux users have the gawk
d) nawk does not provide the additional capabilities in comparison of awk

View Answer

Answer: d [Reason:] None.

2. An awk program can be run by
a) including the program in the command that runs awk
b) putting it into a file and run with a command
c) running an executable awk script
d) all of the mentioned

View Answer

Answer: d [Reason:] The method used to run awk program depends on the program size and input files.

3. Which one of the following is not true?
a) in typical awk program, all input is read either from standard input or specified files
b) awk language divides its input into records and fields
c) awk reads an input record and the record is automatically seperated by the interpreter into pieces called “fields”
d) the number of fields need to be a constant

View Answer

Answer: d [Reason:] The number of fields does not need to be a constant.

4. What is the meaning of $ sign in awk programming?
a) the word following is the name of variable
b) we are refering to a field or column in the current line
c) $ sign is used for comment
d) none of the mentioned

View Answer

Answer: b [Reason:] None.

5. In awk program, the statement “print” with no items
a) is equivalent to “print $0”
b) prints the entire current record
c) is equivalent to “print $0” & prints the entire current record
d) none of the mentioned

View Answer

Answer: c [Reason:] None.

6. The print and printf statements can be told to send their output to other place except standard output, is called
a) redirection
b) redistribution
c) reinsertion
d) none of the mentioned

View Answer

Answer: a [Reason:] None.

7. The command “awk {print $1} san.txt” will
a) print the first line of file san.txt
b) print the first field of every line in san.txt
c) generate syntax error
d) none of the mentioned

View Answer

Answer: b [Reason:] None.

8. What is the output of the command awk ‘BEGIN {printf “%cn”,65}’
a) A
b) 65
c) syntax error
d) none of the mentioned

View Answer

Answer: a [Reason:] The ASCII value of A is 65.

9. Which one of the following statement is not true about the format-control letters for printf statement in awk program?
a) “c” prints a number as an ASCII character
b) “d” prints a decimal integer
c) “h” prints an unsigned hexadecimal integer
d) “o” prints an unsigned octal integer

View Answer

Answer: c [Reason:] “x” prints and unsigned hexadecimal integer

10. Which command on the command line provides the same output as this executable awk script?

  1.     #! /usr/bin/awk -f
  2.     BEGIN {
  3.         print "aidlo"
  4.     }

a) awk ‘BEGIN {print “aidlo”}’
b) awk ‘print “aidlo”‘
c) awk ‘print {aidlo}’
d) none of the mentioned

View Answer

Answer: a [Reason:] None.

Linux MCQ Set 3

1. The break statement
a) jumps out of the innermost for loop
b) jumps out of the innermost while loop
c) jumps out of the innermost do-while loop
d) all of the mentioned

View Answer

Answer: d [Reason:] None.

2. Which statement skips over the rest of the loop body, causing the next cycle around the loop to begin immediately?
a) continue
b) break
c) next
d) none of the mentioned

View Answer

Answer: a [Reason:] None.

3. The next statement
a) immediately stops processing the current record
b) go to the next record
c) immediately stops processing the current record & go to the next record
d) none of the mentioned

View Answer

Answer: c [Reason:] None.

4. If the argument is supplied to the exit statement,
a) its value is used as the exit status code for the awk process
b) syntax error will generate
c) exit returns status 0
d) exit returns status 1

View Answer

Answer: a [Reason:] None.

5. Which statement instructs gawk to stop processing the current data file?
a) next
b) nextfile
c) exit
d) exitfile

View Answer

Answer: b [Reason:] None.

6. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a=5
  4.        while (a<5) {
  5.            print "aidlo"
  6.            a++;
  7.        }
  8.    }

a) nothing will print
b) “aidlo” will print 5 times
c) program will generate syntax error
d) none of the mentioned

View Answer

Answer: a [Reason:] The condition of while statement is false so commands inside the loop will not execute. Output: :/home/aidlo# ./test.awk :/home/aidlo#

7. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a=0
  4.        do {
  5.            print "aidlo"
  6.            a++
  7.        } while (a<5)
  8.    }

a) “aidlo” will print 4 times
b) “aidlo” will print 5 times
c) nothing will print
d) syntax error

View Answer

Answer: b [Reason:] None. Output: :/home/aidlo# ./test.awk aidlo aidlo aidlo aidlo aidlo :/home/aidlo#

8. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a=6
  4.        do {
  5.            print "aidlo"
  6.            a++
  7.        } while (a<5)
  8.    }

a) nothing will print
b) “aidlo” will print 5 times
c) “aidlo” will print 4 times
d) “aidlo” will print only 1 time

View Answer

Answer: d [Reason:] Even the condition is false of do-while loop, the body is executed once. Output: :/home/aidlo# ./test.awk aidlo :/home/aidlo#

9. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        for(i=0;i<=5;i++) {
  4.            print i
  5.            i++
  6.        }
  7.    }

a) 0,2,4 will print
b) 1,3,5 will print
c) 1,2,3,4,5 will print
d) syntax error because i is not initialised

View Answer

Answer: a [Reason:] None. Output: :/home/aidlo# ./test.awk 0 2 4 :/home/aidlo#

10. The command “awk ‘{if (“9″>”10”) print “aidlo” else print “linux”}’”
a) will print “aidlo”
b) will print “linux”
c) will generate syntax error
d) none of the mentioned

View Answer

Answer: c [Reason:] Semicolon is required just before the else statement to parse the statement. Output: :/home/aidlo# awk ‘{if (“9″>”10”) print “aidlo” else print “linux”}’ awk: {if (“9″>”10”) print “aidlo” else print “linux”} awk: ^ syntax error :/home/aidlo#

Linux MCQ Set 4

1. Which one of the following statement is not true?
a) awk’s built-in functions can be categorised into three categories: numeric, string and I/O
b) built-in functions are always available to call
c) extra arguments to built-in function causes syntax error
d) we can also define the function in awk program

View Answer

Answer: c [Reason:] Extra arguments to built-in function causes fatal error.

2. What is the difference between the built-in functions rand() and srand() in awk programming?
a) rand() generates the random number but srand() does not generate the random number
b) rand() generates the same random number always whenever the program runs but srand() generates the different
c) srand() requires the seed() function but rand() does not require to produce the same result
d) none of the mentioned

View Answer

Answer: b [Reason:] None.

3. Which built-in function returns the arctangent of a/b in radians.
a) atan2(a/b)
b) atan(a/b)
c) atan_2(a/b)
d) none of the mentioned

View Answer

Answer: a [Reason:] None.

4. Which built-in function divides string into pieces seperated by fieldsep and stores the pieces in array?
a) split()
b) divide()
c) index()
d) sub()

View Answer

Answer: a [Reason:] None.

5. The built-in function tolower()
a) converts all lowercase characters into uppercase characters
b) returns the string with all lowercase characters
c) changes the nonalphabetic characters
d) none of the mentioned

View Answer

Answer: b [Reason:] None.

6. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        print log(1)
  4.    }

a) 0
b) syntax error
c) fatal error
d) segmentation fault

View Answer

Answer: a [Reason:] The function log() is built-in function and need not to be defined. This function calculates the natural logarithm of positive numbers. Output: :/home/aidlo# ./test.awk 0 :/home/aidlo#

7. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        print index("aidlo","linux")
  4.    }

a) aidlo linux
b) aidlo
c) 0
d) none of the mentioned

View Answer

Answer: c [Reason:] The function index() searches the string “aidlo” for the first occurence of the string “linux”. The function usually returns the character position but here the string is not found, hence function returns 0. Output: :/home/aidlo# ./test.awk 0 :/home/aidlo#

8. What is the output of this pogram?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        system("date")
  4. 	   print "aidlo"
  5.    }

a) the program will execute the date command and then program will print “aidlo”
b) program will generate fatal error because function system() is neither defined nor built-in function
c) program will generate syntax error because the syntax of function system() is wrong
d) none of the mentioned

View Answer

Answer: a [Reason:] The function system() allow to execute operating system command and then return to the awk program. Output: :/home/aidlo# ./test.awk Wed Apr 17 10:22:47 IST 2013 aidlo :/home/aidlo#

9. What is the output of the program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a=int(2.5)
  4.        print (a*20)
  5.    }

a) 50
b) 40
c) a*20
d) syntax error

View Answer

Answer: b [Reason:] The function int() returns the integer part of the value. In this program it returns 2. Output: :/home/aidlo# ./test.awk 40 :/home/aidlo#

10. What is the output of the program?

  1.     #! /usr/bin/awk -f
  2.     BEGIN {
  3.        print toupper("Aidlo_1_$")
  4.     }

a) Aidlo_1_$
b) Aidlo 1 $
c) Aidlo_1_$
d) Aidlo

View Answer

Answer: a [Reason:] None. Output: :/home/aidlo# ./test.awk Aidlo_1_$ :/home/aidlo#

Linux MCQ Set 5

1. In awk, the built-in variable FS is
a) input field seperator
b) output field seperator
c) record seperator
d) subscript seperator

View Answer

Answer: a [Reason:] None.

2. What is FNR?
a) FNR is the current record number in the current file
b) FNR is the number of fields in the current input record
c) FNR is an array contains the value of environment
d) None of the mentioned

View Answer

Answer: a [Reason:] None.

3. RSTART is set by invoking the
a) match function
b) index function
c) asort function
d) split function

View Answer

Answer: a [Reason:] None.

4. Which one of the following is used by awk to control the conversion of numbers to string?
a) RS
b) OFMT
c) SUBSEP
d) RSTART

View Answer

Answer: b [Reason:] None.

5. In awk program, the name of the array can not be same with the
a) name of variable
b) value of the array element
c) name of variable & value of the array element
d) none of the mentioned

View Answer

Answer: a [Reason:] None.

6. What is the output of the program?

  1.    #! /usr/bin/awk -f
  2.    #This filename is text.awk
  3.    BEGIN {
  4.        print FILENAME
  5.    }

a) test.awk
b) program will print nothing
c) syntax error
d) fatal error

View Answer

Answer: b [Reason:] The built-in variable FILENAME is the name of file that awk is currently reading and in this program there is no file listed on the command line. Output: :/home/aidlo# ./test.awk

:/home/aidlo#

7. What is the output of the program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a[1]="aidlo"
  4.        a[2]="aidlo"
  5.        for(i=1;i<3;i++) {
  6.            print a[i]
  7.        }
  8.    }

a) “aidlo” will print 2 times
b) “aidlo” will print 3 times
c) program will generate error becasue 2 array elements have the same value
d) program will generate syntax error

View Answer

Answer: a [Reason:] None. Output: :/home/aidlo# ./test.awk aidlo aidlo :/home/aidlo#

8. What is the output of the program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a[1]="aidlo"
  4.        delete a[1]
  5.        print a[1]
  6.    }

a) program will print “aidlo”
b) program will print nothing
c) program will generate syntax error
d) program will generate fatal error

View Answer

Answer: b [Reason:] The delete command deletes the array element. Output::/home/aidlo# ./test.awk

:/home/aidlo#

9. What is the output of the program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a["linux","MCQ"]="aidlo"
  4.        print a["linux","MCQ"]	   
  5.    }

a) aidlo
b) linux MCQ
c) a[“linux”,”MCQ”].
d) syntax error

View Answer

Answer: a [Reason:] None. Output: :/home/aidlo# ./test.awk aidlo :/home/aidlo#

10. What is the output of the program?

  1.     #! /usr/bin/awk -f
  2.     BEGIN {
  3.         a[1,1]=0
  4.         a[1,2]=1
  5.         a[2,1]=2
  6.         a[2,2]=3
  7. 	for(i=1;i<3;i++) {
  8. 	    for(j=1;j<3;j++) {
  9. 	    print a[i,j]
  10. 	    }
  11. 	}
  12.     }

a) 0 1 2 3
b) 0 2
c) 1 3
d) syntax error

View Answer

Answer: b [Reason:] None. Output: :/home/aidlo# ./test.awk 0 2 :/home/aidlo#