mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-19 03:25:44 +00:00
e388d3bfb5
It might be useful e.g. when removing docker containers: docker ps -a | grep openeir | awk '{print $1 }' | xargs docker rm
18 lines
663 B
Plaintext
18 lines
663 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}'
|
|
|
|
# search for a paragraph containing string
|
|
awk -v RS='' '/42B/' file
|
|
|
|
# display only first column from multi-column text
|
|
echo "first-column second-column third-column" | awk '{print $1}'
|