Let's think about it this way for a second
The most common sed (stream editor) pattern is sed 's/old/new/' file — it replaces 'old' text in the file with 'new' (s = substitute). Adding the g flag (sed 's/old/new/g') replaces every match in each line, whereas without g, only the first match on each line gets replaced. awk, on the other hand, is built for column-based data (CSV, log files) — awk '{print $1}' file prints only the first column ($1) of every line, and you can access columns by number with $2, $3, and so on.
Let's connect this to a real-world scenario
If you want to replace localhost with production-server.com in a config file, use sed 's/localhost/production-server.com/g' config.txt (this only shows the output; adding the -i flag actually edits the file) — it's safer to take a backup before running sed -i. ps aux | awk '{print $2, $11}' extracts just the PID (column 2) and command name (column 11) from the process list — awk is commonly paired with a pipe whenever you need to pull out specific columns from a log or CSV file.
Let's try it together in the terminal
echo "hello world" | sed 's/world/linux/'
sed 's/localhost/prod.example.com/g' config.txt
ps aux | awk '{print $2, $11}'
echo "a,b,c" | awk -F',' '{print $2}'Running sed on hello world will show it transformed into 'hello linux' in the terminal.5-Minute Try-It
Create the line 'I like cats' with echo, then pipe it into sed 's/cats/dogs/' and run it.
A Quick Word of Caution
Before running sed -i (in-place edit) on a production config file, the safest move is to cp file file.backup first.