Linux
Text Processing
Filter, transform, and summarize text streams.
By EZ4Code Team
textawksed
Code
# grep, cut, paste
grep -E "ERROR|WARN" app.log
grep -v "^#" /etc/ssh/sshd_config | grep -v "^$"
cut -d: -f1 /etc/passwd
paste -d, names.txt ages.txt
# awk for column processing
awk -F: '$3 >= 1000 {print $1}' /etc/passwd
awk '{sum += $1} END {print sum}' numbers.txt
# sed for in-place editing
sed -i 's/old/new/g' config.txt
sed -n '10,20p' file.txt
# sort, uniq, head
sort access.log | uniq -c | sort -rn | head -20
# jq for JSON
curl -s https://api.github.com/repos/cli/cli | jq '.stargazers_count'Explanation
grep filters lines, cut extracts fields, and awk processes columns with full programming power for sums and conditions. sed performs stream edits, with -i for in-place file changes. Combining sort, uniq -c, and sort -rn produces frequency rankings, and jq queries JSON like sed for text.
More Linux Snippets
File Operations
Copy, move, link, and search files efficiently.
Permissions & Ownership
Manage read/write/execute bits with chmod and chown.
Process Management
List, signal, and monitor running processes.
Networking
Inspect interfaces, ports, connections, and DNS.
Package Management
Install, update, and search packages on Debian and RHEL.
Disk Usage
Inspect filesystems, large directories, and inodes.