Intermediate LevelLinux Commands & SysAdmin
How do sed hold space and pattern space buffer registers process multi-line text?
❓ Interview Prompt: Explain sed internal registers: Pattern Space (active line) vs Hold Space (secondary buffer), and multi-line commands (h, g, x, N).
Advanced sed processing uses two distinct text memory buffers:
1
Pattern Space: Holds the current line read from input.
2
Hold Space: A secondary persistent buffer used for temporary storage.
Multiline Buffer Commands:
•
'h': Copy Pattern Space into Hold Space.
•
'g': Copy Hold Space into Pattern Space.
•
'x': Exchange (swap) Pattern and Hold spaces.
•
'N': Append next input line into Pattern Space for multi-line matching.
Code Implementation Example
bash
# Reverse line order of a file (emulating tac) using sed hold space
sed -n '1h;1!G;$p;h' file.txt💡Manipulating multiline text registers using sed hold space.
🎯 Interview Key Takeaway
Use sed hold space commands (h, g, x) when complex text transformations require buffering across multiple lines.
#sed#Hold Space#Pattern Space#Intermediate
Back to all Linux Commands & SysAdmin Questions→