awk 'NR>=2 {print NR " - " $0}' mary.txt $ cat mary.txt Mary had a little lamb Little lamb little lamb Mary had a little lamb Whose fleece was white as snow $ cat skipfirstline.awk NR>=2 {print NR " - " $0} awk -f skipfirstline.awk mary.txt $ cat presidents-by-height.tsv tallest prs nbr Name Hgt in Inches Hgt in Centimeters 1 16 Abraham Lincoln 6 ft 4 in 193 cm 2 36 Lyndon B. Johnson 6 ft 3 1⁄2 in 192 cm 3 45 Donald Trump 6 ft 3 in 191 cm 4 3 Thomas Jefferson 6 ft 2 1⁄2 in 189 cm 5 1 George Washington 6 ft 2 in 188 cm 5 21 Chester A. Arthur 6 ft 2 in 188 cm 5 32 Franklin D. Roosevelt 6 ft 2 in 188 cm 5 41 George H. W. Bush 6 ft 2 in 188 cm 5 42 Bill Clinton 6 ft 2 in 188 cm 10 7 Andrew Jackson 6 ft 1 in 185 cm 10 35 John F. Kennedy 6 ft 1 in 185 cm 10 40 Ronald Reagan 6 ft 1 in 185 cm 10 44 Barack Obama 6 ft 1 in 185 cm awk -F "\t" -f presidents.awk presidents-by-height.tsv $ cat presidents.awk { if (length($3) <= 8) print $1 "\t" $2 "\t\t" $3 "\t\t\t" $4 "\t" $5 "\t" $6 else if (length($3) <= 15) print $1 "\t" $2 "\t\t" $3 "\t\t" $4 "\t" $5 "\t" $6 else print $1 "\t" $2 "\t\t" $3 "\t" $4 "\t" $5 "\t" $6 } awk -F "\t" -f presidents-printf.awk presidents-by-height.tsv $ cat presidents-printf.awk { printf "%-8s %-8s %-23s %-14s %-8s \n", $1, $2, $3, $4, $5 } $ cat grades.txt Jamie,92,78,95,82,100 Dana,91,88,92,87,93 Danny,89,92,84,97,91 Alex,85,74,85,100,78 Charlie,93,84,78,92,87 Tatum,95,93,72,100,92 Jordan,78,94,81,84,100 Shae,82,85,91,78,100 Payton,92,73,80,92,100 Riley,89,89,97,91,81 Terry,85,92,97,87,93 awk -f findavg.awk grades.txt $ cat findavg.awk BEGIN { FS=","; hdr_line="Name "; for (i=1; i<=5; i++ ) { hdr_line = hdr_line "\ttest" i ; } hdr_line = hdr_line "\t\tavg"; print " "; print hdr_line; print "------ \t------\t------\t------\t------\t------\t\t----"; } { main_line=$1; std_test_tot=0; for ( i=2; i<=6; i++ ) { main_line = main_line "\t" $i ; std_test_tot += $i; test_total[i] += $i; } std_avg = int(std_test_tot / 5); class_avg_tot += std_avg; print main_line "\t\t"std_avg; } END { avg_line="Avg\t"; for ( i=2; i<=6; i++ ) { avg_line = avg_line int(test_total[i] / NR) "\t"; } print "------ \t------\t------\t------\t------\t------\t\t----"; print avg_line "\t" int(class_avg_tot / NR); print " "; } $ ./rectangle.awk $ which awk /usr/bin/awk $ cat rectangle.awk #!/usr/bin/awk -f # This script will caculate the area of a rectangle # function area return the height times the width function area(height,width){ return height*width } #function check number - check the value in to see if it is numeric function chk_numeric(value_in){ if (value_in ~ /^[[:digit:]]/) return 1; else return 0; } # Starts execution BEGIN { print "Enter the value of height:" getline h < "-" while ( chk_numeric(h) == 0 ) { print "Height must be numeric - Enter the value of height:" getline h < "-" } print "Enter the value of width:" getline w < "-" while ( chk_numeric(w) == 0 ) { print "Width must be numeric - Enter the value of width:" getline w < "-" } print "The area of your rectangle is " area(h,w) }