ENTRY
[ESC]Check out this useful awk one-liner that prints a multiplication table in your terminal:
awk 'BEGIN{for(i=1;i<=20;i++){for(j=1;j<=20;j++) printf "%4d", i*j; print ""}}'
And here's a more advanced version, with colour and additional styling:
awk 'BEGIN{n=12; ESC="\033["; RESET=ESC"0m"; BOLD=ESC"1m"; RED=ESC"31m"; CYAN=ESC"36m"; printf BOLD" |"; for(j=1;j<=n;j++) printf BOLD"%4d", j; print "\n----+" sprintf("%s","----"*n); for(i=1;i<=n;i++){printf BOLD"%3d |", i; for(j=1;j<=n;j++){v=i*j; color=(i==j?RED:(v%5==0?CYAN:"")); printf "%s%4d%s", color, v, RESET} print ""}}'
3 replies
Log in to read the replies and join the conversation