emp.data Beth 4.00 0 emp.data Dan 3.75 0 emp.data Kathy 4.00 10 emp.data Mark 5.00 20 emp.data Mary 5.50 22 emp.data Susie 4.25 18 05.awk { print \$1, \$3 } 28.awk { print NF, \$1, \$NF } 06.awk { print \$1, \$2 * \$3 } 07.awk { print NR, \$0 } 10.awk { print "total pay for", \$1, "is", \$2 * \$3 } 11.awk { printf("total pay for %s is \$%.2f\n", \$1, \$2 * \$3) } 11a.awk { printf("%-8s \$%6.2f\n", \$1, \$2 * \$3) } 08.sh awk '{ printf("%6.2f %s\n", \$2 * \$3, \$0) }' emp.data | sort 12.awk \$2 >= 5 13.awk \$2 * \$3 > 50 { printf("\$%.2f for %s\n", \$2 * \$3, \$1) } 14.awk \$1 == "Susie" 15.awk /Susie/ 20.awk \$2 >= 4 || \$3 >= 20 21.awk \$2 >= 4 21.awk \$3 >= 20 22.awk !(\$2 < 4 && \$3 < 20) 26.awk NF != 3 { print \$0, "number of fields is not equal to 3" } 26.awk \$2 < 3.35 { print \$0, "rate is below minimum wage" } 26.awk \$2 > 10 { print \$0, "rate exceeds \$10 per hour" } 26.awk \$3 < 0 { print \$0, "negative hours worked" } 26.awk \$3 > 60 { print \$0, "too many hours worked" } 30.awk BEGIN { print "NAME RATE HOURS"; print "" } 30.awk { print } 31.awk \$3 > 15 { emp = emp + 1 } 31.awk END { print emp, "employees worked more than 15 hours" } 31a.awk END { print NR, "employees" } 32.awk { pay = pay + \$2 * \$3 } 32.awk END { print NR, "employees" 32.awk print "total pay is", pay 32.awk print "average pay is", pay/NR 32.awk } 33.awk \$2 > maxrate { maxrate = \$2; maxemp = \$1 } 33.awk END { print "highest hourly rate:", maxrate, "for", maxemp } 34.awk { names = names \$1 " " } 34.awk END { print names } 33a.awk { last = \$0 } 33a.awk END { print last } 40.awk { print \$1, length(\$1) } 40a.awk { nc = nc + length(\$0) + 1 40a.awk nw = nw + NF 40a.awk } 40a.awk END { print NR, "lines,", nw, "words,", nc, "characters" } 41.awk \$2 > 6 { n = n + 1; pay = pay + \$2 * \$3 } 41.awk END { if (n > 0) 41.awk print n, "employees, total pay is", pay, 41.awk "average pay is", pay/n 41.awk else 41.awk print "no employees are paid more than \$6/hour" 41.awk } interest1.awk # interest1 - compute compound interest interest1.awk # input: amount rate years interest1.awk # output: compounded value at the end of each year interest1.awk interest1.awk { i = 1 interest1.awk while (i <= \$3) { interest1.awk printf("\t%.2f\n", \$1 * (1 + \$2) ^ i) interest1.awk i = i + 1 interest1.awk } interest1.awk } forint.awk # interest2 - compute compound interest forint.awk # input: amount rate years forint.awk # output: compounded value at the end of each year forint.awk forint.awk { for (i = 1; i <= \$3; i = i + 1) forint.awk printf("\t%.2f\n", \$1 * (1 + \$2) ^ i) forint.awk } 50.awk # reverse - print input in reverse order by line 50.awk 50.awk { line[NR] = \$0 } # remember each input line 50.awk 50.awk END { i = NR # print lines in reverse order 50.awk while (i > 0) { 50.awk print line[i] 50.awk i = i - 1 50.awk } 50.awk } 51.awk # reverse - print input in reverse order by line 51.awk 51.awk { line[NR] = \$0 } # remember each input line 51.awk 51.awk END { for (i = NR; i > 0; i = i - 1) 51.awk print line[i] 51.awk } 61.awk END { print NR } 62.awk NR == 10 66.awk { print \$NF } 63.awk { field = \$NF} 63.awk END { print field } 64.awk NF > 4 65.awk \$NF > 4 67.awk { nf = nf + NF } 67.awk END { print nf } 68.awk /Beth/ { nlines = nlines + 1 } 68.awk END { print nlines } 69.awk \$1 > max { max = \$1; maxline = \$0 } 69.awk END { print max, maxline } 70.awk NF > 0 71.awk length(\$0) > 80 72.awk { print NF, \$0 } 73.awk { print \$2, \$1 } 74.awk { temp = \$1; \$1 = \$2; \$2 = temp; print } 75.awk { \$1 = NR; print } 76.awk { \$2 = ""; print } 77.awk { for (i = NF; i > 0; i = i - 1) printf("%s ", \$i) 77.awk printf("\n") 77.awk } 78.awk { sum = 0 78.awk for (i = 1; i <= NF; i = i + 1) sum = sum + \$i 78.awk print sum 78.awk } 79.awk { for (i = 1; i <= NF; i = i + 1) sum = sum + \$i } 79.awk END { print sum } 80.awk { for (i = 1; i <= NF; i = i + 1) if (\$i < 0) \$i = -\$i 80.awk print 80.awk }