You are on page 1of 2

Assignment from Unit-4

1. What are the modes of vi editor? Explain the importance of each mode.
2. Discuss different wondow positioning according to vi.
3. List the insert and delete functions of vi.
4. Which block commands are used and what is the purpose of ex commands?
5. Describe the search pattern, direction of search and find-replace, yank-paste in vi.
6. What is the purpose of using awk the advanced filters?
7. What will be the output cosidering the file emp.lst :

i) awk -F”|” ‘/sales/ {print $2,$3,$4,$6}’ emp.lst


ii) awk -F”|” ‘NR == 3, NR == 6 {print NR,$2,$3,$6} emp.lst
iii) awk -F”|” ‘/[aA]gg?[ar]+wal/ { printf “%3d %-20s %-12s %d \n”, NR,$2,$3,$6
}’ emp.lst
iv) printf “%s %-10s %-12s %-8s\n”, $1, $3, $4, $6 | “sort”
v) awk –F”|” ‘$3 == “director” || $3 == “chairman” { printf “%-20s %-12s %d \n”,
$2, $3, $6 }’ emp.lst
vi) awk -F”|” ‘$6 > 7500 { printf “%-20s %-12s %d\n”, $2, $3, $6 }’ emp.lst
vii) awk -F”|” ‘$3 == “director” { printf “%-20s %-12s %d %d %d\n”, $2, $3, $6,
$6*0.4, $6*0.15 }’ emp.lst
viii) BEGIN {
printf “\t\t Employee abstract\n\n”
}
$6 > 7500
{ kount++ ; tot+=$6
printf “%3d %-20s %-12s %d\n”, kount, $2, $3, $6
}
END {
printf “\n\t the average basic pay is %6d\n”, tot / kount
}
ix) BEGIN { FS = “|”
printf “ Basic DA HRA Gross”
} /sales | marketing/ {
da = 0.5 * $6 ; hra = 0.2 * $6 ; gp = $6 + da + hra
tot[1] += $6 ; tot[2] += da ; tot[3] += hra ; tot[4] += gp kount++ }
END {
printf “\t Average %5d %5d %5d %5d \n“, tot[1] / kount, tot[2] /
kount, tot[3] / kount, tot[4] / kount
}
x) BEGIN {
direction[“N”] = “North” ; direction[“S”] = “South” ;
direction[“E”] = “East” ; direction[“W”] = “West” ;
printf(“ N is %s and W is %s \n”, direction[“N”], direction[“W”]);
}
xi) function find_min(num1, num2)
{
if (num1 < num2)
return num1
return num2
}
function find_max(num1, num2) {
if (num1 > num2)
return num1
return num2
}

function main(num1, num2){

result = find_min(10, 20)


print "Minimum =", result
result = find_max(10, 20)
print "Maximum =", result
}
BEGIN {
main(10, 20)
}
xii) awk 'BEGIN {
PI = 3.14159265
param = 60
result = cos(param * PI / 180.0);

printf "The cosine of %f degrees is %f.\n", param, result


}'
xiii) awk 'BEGIN {
print "Random num1 =" , rand()
print "Random num2 =" , rand()
print "Random num3 =" , rand()
}'
xiv) awk 'BEGIN { PI = 3.14159265 ; param = 30.0 ;
result = sin(param * PI /180)
printf "The sine of %f degrees is %f.\n", param, result }'

xv) awk 'BEGIN { param = 1024.0 ; result = sqrt(param) ;


printf "sqrt(%f) = %f\n", param, result }'

8. Write a program to find the gross salary of employees where in the emp.lst file :

i) 90% DA and 20% HRA for basic salary more than 10000

ii) 80% DA and 10% HRA for basic salary less than 10000

9. Write a program using awk to find the even and odd numbers from 1 to 10.

10. Write a program using awk to search a file by taking a pattern from the command line.

You might also like