# 1.awk # This is an awk program to print each entire line of input {print $0} # or, more simply {print} # 2.awk # This awk program prints the 1st and 3rd words # of each line of input {print $1 $3} #!/usr/bin/awk -f #3.awk # This awk program prints the 1st and LAST words # of each line of input # with a SPACE in between {print $1 " " $NF} #!/usr/bin/awk -f # 4.awk # This awk program prints the FIRST and LAST FIELD # of each line of input # with a SPACE in between {print $1 " " $NF} #!/usr/bin/awk -f # 5.awk # This awk program prints the ROW NUMBER and NUMBER OF FIELDS # of each line of input # with a SPACE in between # {print NR " " NF} #!/usr/bin/awk -f # 5b.awk # This awk program prints the ROW NUMBER and NUMBER OF FIELDS # of each line of input # with a SPACE in between # ASSUMES FIELDS ARE SEPARATED BY A SINGLE SEMI-COLON BEGIN {FS=";";} {print NR " " NF} #!/usr/bin/awk -f # 5c.awk # This awk program prints the FIRST and LAST FIELD # of each line of input # with a SPACE in between # ASSUMES FIELDS ARE SEPARATED BY A SINGLE SEMI-COLON BEGIN {FS=";";} {print $1 " " $NF} #!/usr/bin/awk -f # 6.awk # This awk program prints the the ENTIRE LINE of # of each line of input of LESS THAN 50 CHARACTERS BEGIN { print "Here are the lines of less than 50 characters:";} length < 50 {print $0} END { print "Have a nice day.";} #!/usr/bin/awk -f # 7.awk # This awk program prints the the ENTIRE LINE of # of each line of input that has one or more numerals in it. BEGIN { print "Here are the lines that match [0-9]:";} /[0-9]+/ {print $0} END { print "Have a nice day.";} #!/usr/bin/awk -f # 8.awk # This awk program prints the the ENTIRE LINE of # of each line of input that has one or more numerals in it. BEGIN { print "Here are the lines that match ~[0-9]:";} $0~/[0-9]+/ {print $0} END { print "Have a nice day.";} #!/usr/bin/awk -f # 9.awk # This awk program prints the the ENTIRE LINE of # of each line of input that has NO NUMERALS in it. BEGIN { print "Here are the lines that match $!~[0-9]:";} $0!~/[0-9]/ {print $0} END { print "Have a nice day.";} #!/usr/bin/awk -f # 10.awk # This awk program prints the the ENTIRE LINE of # of each line of input that has NO LETTERS it. # It also COUNTS THE NUMBER OF LINES PRINTED. BEGIN { print "Here are the lines that match $!~[A-Za-z]:";} $0!~/[A-Za-z]/ {print $0; count++;} END { printf "There were %d matches \n",count ;} #!/usr/bin/awk -f # 11.awk # This awk program prints FIRST FIELD # of each line of input that STARTS WITH # one or 1 or eleven # It also COUNTS THE NUMBER OF LINES PRINTED. BEGIN { print "Here are the lines that match /^1|^"eleven"|^one/ ";} /^1|^"eleven"|^one/ {print $1; count++;} END { printf "There were %d matches \n",count ;} #!/usr/bin/awk -f # 12.awk # This awk program prints FIRST FIELD # of each line of input that STARTS WITH # one or 1 or eleven # It also COUNTS THE NUMBER OF LINES PRINTED. BEGIN { print "Here are the lines that match /^1|^"eleven"|^one/ ";} /^1|^"eleven"|^one/ {print $1; count++;} END { printf "There were %d matches \n",count ;}