Text Processing & Shell Tools

0%
Text & Shellgrepawksedcutsortuniqxargsfind

Text Processing & Shell Tools

7 interactive questions

Text & ShellQuestion
grepawksedcutsortuniqxargsfind

`grep` vs `awk` vs `sed` — when to use each?

Click to reveal answer
Text & ShellAnswer

grep — filter lines matching a pattern. awk — field-based processing, columns, math, structured text. sed — stream editing, in-place changes, simple substitutions. 🎯 awk for CSV/column data; sed for line edits; grep for search.

Text & ShellQuestion
grepawksedcutsortuniqxargsfind

How do you extract column 3 from a CSV with awk?

Click to reveal answer
Text & ShellAnswer

awk -F',' '{print $3}' file.csv. For header skip: awk -F',' 'NR>1 {print $3}'.

Text & ShellQuestion
grepawksedcutsortuniqxargsfind

What does `xargs` do?

Click to reveal answer
Text & ShellAnswer

Builds and executes command lines from standard input. Converts input into arguments. find . -name "*.log" | xargs rm deletes them. -I {} placeholder: xargs -I {} cp {} /backup/. ⚠️ Use -0 with find -print0 for filenames with spaces.

Text & ShellQuestion
grepawksedcutsortuniqxargsfind

How do you replace all occurrences of a string in files recursively?

Click to reveal answer
Text & ShellAnswer

sed -i 's/old/new/g' $(grep -rl 'old' .) or find . -type f -exec sed -i 's/old/new/g' {} +.

Text & ShellQuestion
grepawksedcutsortuniqxargsfind

`cut` vs `awk` for column extraction?

Click to reveal answer
Text & ShellAnswer

cut -d',' -f2 is simpler for single-char delimiters. awk -F',' '{print $2}' handles multi-char delimiters, regex, and complex logic.

Text & ShellQuestion
grepawksedcutsortuniqxargsfind

How do you sort and deduplicate?

Click to reveal answer
Text & ShellAnswer

sort file | uniq (adjacent dedup). sort -u file (sort + unique). sort -k2,2 -n sorts numerically by column 2.

Text & ShellQuestion
grepawksedcutsortuniqxargsfind

What is `find` and useful predicates?

Click to reveal answer
Text & ShellAnswer

Recursively searches files. -name "*.log", -type f (files), -mtime -7 (modified <7 days), -size +100M, -exec cmd {} +, -delete. ⚠️ -exec runs once per file; -exec ... + batches.