Back to Home
Linux
Commands for searching, filtering, and manipulating text
grepsedawktext
Linux Text Processing
Powerful commands for text manipulation and searching.
grep - Search Text
# Search for pattern in file
grep "pattern" file.txt
# Case-insensitive search
grep -i "pattern" file.txt
# Recursive search in directories
grep -r "pattern" /path/to/dir
# Show line numbers
grep -n "pattern" file.txt
# Invert match (show non-matching lines)
grep -v "pattern" file.txt
sed - Stream Editor
# Replace first occurrence per line
sed 's/old/new/' file.txt
# Replace all occurrences
sed 's/old/new/g' file.txt
# Edit file in place
sed -i 's/old/new/g' file.txt
# Delete lines matching pattern
sed '/pattern/d' file.txt
awk - Pattern Processing
# Print specific column
awk '{print $1}' file.txt
# Print multiple columns
awk '{print $1, $3}' file.txt
# Field separator
awk -F':' '{print $1}' /etc/passwd
# Sum a column
awk '{sum += $1} END {print sum}' numbers.txt
Other Useful Commands
# Count lines, words, characters
wc -l file.txt
# Sort lines
sort file.txt
# Remove duplicate lines
sort -u file.txt
# First/last lines
head -n 10 file.txt
tail -n 10 file.txt
# Follow file updates in real-time
tail -f logfile.log