3.1 grep: Pattern Searching
grep "pattern" file — find lines matching a pattern. grep -i (case-insensitive), -r (recursive), -n (line numbers), -c (count), -v (invert — lines NOT matching), -l (filenames only). grep -E for extended regex. egrep shortcuts. "Find all ERROR lines in all log files" — the daily task grep solves.
3.2 Regular Expressions
Basic regex: . (any char), * (zero or more), ^ (start), $ (end), [abc] (character class), [^abc] (negation). Extended regex: + (one or more), ? (zero or one), {n} (exactly n), | (alternation), () (grouping). Regex is used in grep, sed, awk, and every programming language. The 10 patterns that cover 90% of real-world regex use.
3.3 sort, cut, uniq, tr, tee
sort (alphabetical, -n numeric, -r reverse, -k field, -t delimiter). cut -d',' -f2 (extract fields from CSV). uniq (remove adjacent duplicates — always sort first). tr (translate/delete characters: tr 'a-z' 'A-Z'). tee (write to file AND stdout simultaneously). Combining these with pipes for data processing.
3.4 find: The Most Powerful File Search
find /path -name "*.log" (by name). -type f (files), -type d (directories). -mtime -7 (modified in last 7 days), -size +100M (larger than 100MB). -exec command {} \; (execute command on each result). find + xargs for parallel execution. "Find all Python files modified today larger than 1MB" — one find command.
3.5 sed: Stream Editor
sed 's/old/new/' file — substitute first occurrence per line. sed 's/old/new/g' — all occurrences. sed -i for in-place editing. Address ranges: sed '5,10d' (delete lines 5–10). sed '/pattern/d' (delete matching lines). Practical: update config files, fix formatting, batch text replacement. sed is the command-line find-and-replace.
3.6 awk: Pattern-Action Programming
awk '{print $1, $3}' file — extract columns 1 and 3. Field separator: awk -F',' (CSV parsing). Patterns: awk '$3 > 100' (filter by condition). Built-in variables: NR (line number), NF (field count), $NF (last field). BEGIN/END blocks. Calculations: awk '{sum+=$3} END{print sum}'. awk turns structured text into analysed data — the command-line equivalent of a spreadsheet.
Placement relevance: "Write a command to find the 5 most common error types in a log file" — this is grep + sort + uniq -c + sort -rn + head, and it's asked in every systems/DevOps interview. Regular expressions are tested everywhere — Linux, Python, JavaScript, SQL. sed and awk questions appear in advanced Linux and automation interviews.