RE Capital's Visionary Leadership under Newman Leech
7
1. 18IS33-UNIX and Shell Programming (Scheme and Solution) Page 7
Signature of the QuestionPaperSetter:
:
Signature of Scrutinizer
Subject Titles: UNIX and Shell Programming. Subject Code: 18IS33
Q.No. Solutions Marks
Allotted
6.c) A here document is a special-purpose code block. It uses a form of I/O redirection to
feed a command list to an interactive program or a command, such as ftp, cat, or
the ex text editor.
COMMAND <<InputComesFromHERE
...
...
InputComesFromHERE
6M
7.a) BUILT-IN VARIABLES
i) FS ii) OFS iii) NF iv)FILENAME 6M
7.b) The if statement can be used when the && and || are found to be inadequate for certain tasks.
Its behavior is well known to all programmers. The statement here takes the form:
if (condition is true) {
Statement }
else {
Statement
}
The while loop has a similar role to play; it repeatedly iterates the loop until the command
succeeds. For example, the previous for loop used for centering text can be easily replaced
with a while construct:
k=0
while (k < (55 – length($0))/2) {
printf “%s”,“ ”
k++ }
print $0
4M
4M
7.c) Associative arrays :Even though we used integers as subscripts in the tot [ ] array, awk doesn’t
treat array indexes as integers. Awk arrays are associative, where information is held as key- value
pairs. The index is the key that is saved internally as a string. When we set an array element using
mon[1]=”mon”, awk converts the number 1 to a string.
$nawk ‘BEGIN {
print “HOME” “=” ENVIRON[“HOME”]
print “PATH” “=” ENVIRON[“PATH”] }’
6M