Stream editing with sedCommand line · 0/4 steps

Find and replacestep 1 of 4 · intermediate

Support

The command is shown. Click it to run, or type your own.

By the end of this lesson you can
  • Substitute text with sed 's/old/new/'
  • Replace every match on a line with the g flag
  • Delete lines by address, e.g. sed '1d' to drop a header
  • Print a range of lines with sed -n '2,4p'

Before you startComfort reading and piping text: cat, grep, and |.

s/OLD/NEW/ substitutes the first match on each line. Let's rename chr to chromosome.

Replace chr with chromosome in variants.tsv.

beforechr1 BRCA1 chr7 TP53
sed s/chr/chromosome/g
afterchromosome1 BRCA1 chromosome7 TP53
sed reads the text line by line and rewrites each match as it streams past; the file on disk is untouched.
Key concept

"Stream editor" means sed never changes the file on disk, it edits the text as it flows past and prints the result. To keep the changes you redirect them to a new file (sed '...' in.tsv > out.tsv). Your original is always safe.

workspace · terminal

Type a command, or click the suggested one. ↑/↓ recall history, Tab completes file names. New to this? Hit Explain this command to see it in plain English.

…
workspace/shared/data0 files
Booting the WebAssembly runtime…
Command line0 / 4 stepsStep 1WASM shell