| Command | What it does | Example |
awk '{print $1}' access.log | Prints the first column from each line. | awk '{print $1}' access.log |
awk '{print $1, $4, $9}' access.log | Prints selected columns from each line. | awk '{print $1, $4, $9}' access.log |
awk -F',' '{print $1, $3}' users.csv | Uses comma as separator and prints chosen CSV columns. | awk -F',' '{print $1, $3}' users.csv |
awk '$9 >= 500 {print $0}' access.log | Prints only lines where column 9 is 500 or more. | awk '$9 >= 500 {print $0}' access.log |
awk '/ERROR|WARN/' app.log | Prints only lines matching ERROR or WARN. | awk '/ERROR|WARN/' app.log |
awk 'NR==1,NR==20 {print}' app.log | Prints a specific line range. | awk 'NR==1,NR==20 {print}' app.log |
awk '{count[$1]++} END {for (k in count) print k, count[k]}' access.log | Counts repeated values in the first column. | awk '{count[$1]++} END {for (k in count) print k, count[k]}' access.log |
| Command | What it does | Example |
sed 's/localhost/127.0.0.1/g' config.yml | Replaces text in output. | sed 's/localhost/127.0.0.1/g' config.yml |
sed -n '1,20p' file.txt | Prints only the selected line range. | sed -n '1,20p' file.txt |
sed '/DEBUG/d' app.log | Deletes matching lines from output. | sed '/DEBUG/d' app.log |
sed -n '/BEGIN/,/END/p' file.txt | Prints lines between two patterns. | sed -n '/BEGIN/,/END/p' file.txt |
sed 's/[[:space:]]\+$//' file.txt | Removes trailing spaces from each line. | sed 's/[[:space:]]\+$//' file.txt |
sed -i 's/old/new/g' file.txt | Edits the file in place and replaces all matches. | sed -i 's/old/new/g' file.txt |
| Command | What it does | Example |
grep ERROR app.log | awk '{print $1, $2, $NF}' | Finds error lines and prints selected fields. | grep ERROR app.log | awk '{print $1, $2, $NF}' |
ps aux | awk '{print $2, $3, $4, $11}' | head | Shows PID, CPU, memory and command columns. | ps aux | awk '{print $2, $3, $4, $11}' | head |
df -h | awk 'NR==1 || $5+0 > 80' | Shows only filesystems over 80% usage plus header. | df -h | awk 'NR==1 || $5+0 > 80' |
sed -n '1000,1050p' app.log | grep Exception | Prints a line range and filters exceptions. | sed -n '1000,1050p' app.log | grep Exception |