Awk Programming Questions & Answers on Variables & Array for Freshers

1. In awk, the built-in variable FS is

a) input field seperator
b) output field seperator
c) record seperator
d) subscript seperator
Answer: a
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
Answer: a
3. RSTART is set by invoking the

a) match function
b) index function
c) asort function
d) split function
Answer: a
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
Answer: b
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
Answer: a
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
Answer: b

7. What is the output of the program?
  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a[1]="computersprofessor"
  4.        a[2]="computersprofessor"
  5.        for(i=1;i<3;i++) {
  6.            print a[i]
  7.        }
  8.    }
a) “computersprofessor” will print 2 times
b) “computersprofessor” will print 3 times
c) program will generate error becasue 2 array elements have the same value
d) program will generate syntax error
Answer: a

8. What is the output of the program?
  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a[1]="computersprofessor"
  4.        delete a[1]
  5.        print a[1]
  6.    }
a) program will print “computersprofessor”
b) program will print nothing
c) program will generate syntax error
d) program will generate fatal error
Answer: b

9. What is the output of the program?
  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a["linux","MCQ"]="computersprofessor"
  4.        print a["linux","MCQ"]	   
  5.    }
a) computersprofessor
b) linux MCQ
c) a[“linux”,”MCQ”].
d) syntax error
Answer: a
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
Answer: b

Related

Linux Questions & Answers on Shell Special Symbols for Freshers

1. The $ variables in a shell script context designates a) The runtime of the scriptb) Number of command line argumentsc) PID of the shell running the scriptd) The exit status of the shell script ...

C# Question & Answers on Generic Methods for Freshers

1. For the code set given below,which of the following statements are perfectly valid? public class MyContainer<T> where T: class, IComparable { /* insert code here */ } ...

C# Questions & Answers on Fundamental of Generics for Freshers

1. What is meant by the term generics? a) parameterized typesb) classc) structured) interface Answer: a Explanation: The term generics means parameterized types. Parameterized types are important...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item