mirror of
https://github.com/Erreur32/cheat.git
synced 2024-10-31 21:11:07 +01:00
12 lines
473 B
Plaintext
12 lines
473 B
Plaintext
# sum integers from a file or stdin, one integer per line:
|
|
printf '1\n2\n3\n' | awk '{ sum += $1} END {print sum}'
|
|
|
|
# using specific character as separator to sum integers from a file or stdin
|
|
printf '1:2:3' | awk -F ":" '{print $1+$2+$3}'
|
|
|
|
# print a multiplication table
|
|
seq 9 | sed 'H;g' | awk -v RS='' '{for(i=1;i<=NF;i++)printf("%dx%d=%d%s", i, NR, i*NR, i==NR?"\n":"\t")}'
|
|
|
|
# Specify output separator character
|
|
printf '1 2 3' | awk 'BEGIN {OFS=":"}; {print $1,$2,$3}'
|