sed in Bash
The stream editor: substitute, delete, select.
text='the quick brown fox
jumps over the lazy dog'
# s///: substitute the first match per line, /g for all
echo "$text" | sed 's/the/THE/'
echo "$text" | sed 's/the/THE/g'
# address ranges pick which lines to touch; d deletes
echo "$text" | sed '2s/lazy/alert/'
echo "$text" | sed '1d'
# -n plus p prints only what you ask for
echo "$text" | sed -n '/fox/p'
How it works
s/old/new/replaces the first match per line;/gall of them.- Addresses like
2s/...and1dpick their lines. -nwithpprints only the lines you ask for.
Keywords and builtins used here
echo
The run, in numbers
- Lines
- 13
- Characters to type
- 360
- Tokens
- 43
- Three-star pace
- 75 tpm
At the three-star pace of 75 tokens a minute, this run takes about 34 seconds.
Step 2 of 3 in Text tools, step 20 of 26 in Language basics.