Skip to content

Latest commit

 

History

History
23 lines (23 loc) · 578 Bytes

Text_Processing.md

File metadata and controls

23 lines (23 loc) · 578 Bytes

Search with grep

grep "error" /var/log/syslog
grep -r "TODO" ~/projects/

Advanced grep

grep -i "failed" /var/log/auth.log | wc -l  # count failed login attempts

awk examples

ps aux | awk '{print $1, $11}'  # print user and command
cat /etc/passwd | awk -F: '{print $1, $6}'  # print username and home dir

sed examples

sed 's/old/new/g' file.txt  # replace text
sed -n '10,20p' file.txt    # print lines 10-20

Piping chains

cat /var/log/syslog | grep "error" | awk '{print $1, $2, $3}' | sort | uniq