LESSON 5 of 5//Stream Processing
Transforming with sed and awk
sed (stream editor) transforms text line-by-line using patterns. awk is a more powerful text-processing language that works with fields and columns. Together they handle most text manipulation tasks.
sed — find and replacezsh // interactive
# Replace first occurrence on each line
➜~echo 'hello world' | sed 's/hello/goodbye/'
goodbye world
# Replace in-place in a file (macOS syntax)
➜~sed -i '' 's/localhost/0.0.0.0/g' config.txt
awk — column processingzsh // interactive
# Print the second column of output
➜~ls -l | awk '{print $9}'
Desktop
Documents
Downloads
# Sum numbers in a column
➜~awk '{sum += $5} END {print sum}' data.txt
PRACTICE//Try the commands from this lesson
INTERACTIVE_TERMINAL//sandbox
Practice terminal — try the commands from this lesson!
Type 'help' for available commands. Tab completion not available in simulator.
Try: