Advanced Bash

Text Processing

Bash
# Top 10 IP addresses in access log
cat access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -10

# sed find and replace
sed -i 's/old/new/g' file.txt

# awk columns
awk -F: '{print $1}' /etc/passwd

Cron Jobs

Bash
crontab -e
# min hour day month weekday command
0 2 * * * /home/user/backup.sh       # Daily at 2 AM
0 9 * * 1 /home/user/report.sh       # Every Monday
*/5 * * * * /home/user/check.sh      # Every 5 minutes

Debugging

Bash
#!/bin/bash
set -euo pipefail   # Exit on error, undefined vars, pipe failure
set -x              # Print each command

🎉 You have completed the Bash course!