How do you use sed for text processing?

Why Interviewers Ask This

Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.

Answer

sed (stream editor) processes text line by line. Most common use: substitution: sed 's/old/new/' file replaces the first occurrence per line; sed 's/old/new/g' replaces all. sed -i 's/foo/bar/g' file edits the file in-place (add a backup suffix: sed -i.bak). Delete lines: sed '/pattern/d' file. Print specific lines: sed -n '5,10p' file. Insert before a line: sed '/pattern/i\new line'. Append after: sed '/pattern/a\new line'. Multiple expressions: sed -e 's/a/b/' -e 's/c/d/'. Use sed -n to suppress default output and only print explicitly with p.

Common Mistake

Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong Linux / Shell Scripting candidates.