Bash · lesson 17 of 30 · Data, functions and the command lineJoin commands
The sign | passes the output of one command to the next; $( ) puts an output into a text.
17-pipes.sh Download 17-pipes.sh
#!/usr/app/TurboShell/bin/bash
# | gives the output of one command to the next one
echo "lines with ERROR: $(grep -c ERROR nas.log)"
echo "levels:"
cut -d ' ' -f 3 nas.log | sort | uniq -c | sort -rn
echo "days: $(cut -d ' ' -f 1 nas.log | sort -u | wc -l)"
newest=$(tail -n 1 nas.log)
echo "newest: ${newest#* }"
Terminal
$ bash 17-pipes.sh
lines with ERROR: 3
levels:
6 INFO
3 WARN
3 ERROR
days: 3
newest: 18:09:33 ERROR disk 3 read errorExercise
Show the hour with the most log lines.