Pipes and tools: grep, sed, awk, sort
Chain commands with |, and the text tools available to scripts: grep, sed, awk, sort, uniq, cut, tr, wc.
Runs in Zerethon IDE · Bash 5.2
Official Bash documentation ↗
main.sh
grep -c ERROR log.txt
grep -v INFO log.txt | sort | uniq -c | sort -rn
awk '{ count[$1]++ } END { for (k in count) print k, count[k] }' log.txt | sort
sed 's/disk full/disk is full/' log.txt | head -n 2
cut -d' ' -f1 log.txt | sort -u | paste -sd, -
awk 'BEGIN { printf "%.2f\n", 7 / 2 }'
log.txt
INFO start
ERROR disk full
INFO retry
ERROR disk full
WARN slow
Output
2
2 ERROR disk full
1 WARN slow
ERROR 2
INFO 2
WARN 1
INFO start
ERROR disk is full
ERROR,INFO,WARN
3.50
a | bsends the output ofato the input ofb.uniqonly merges lines that are next to each other —sortfirst.awksplits each line into fields$1,$2…, and does decimal arithmetic, which Bash cannot.- The tools are the BusyBox versions of the Alpine image: the common options work, but a few GNU-only options do not (
sed -ion project files would also fail — they are read-only).