sed for Text Editing: Stream Editing Without Opening a File
sed edits text as it flows through a pipeline. After years of using it for find-replace and line deletion, here is what I actually use. sed, the stream editor, applies editing commands to text as it flows through a pipeline. Unlike a text editor, sed never opens a file interactively. It reads input, applies commands, and writes output, which makes it ideal for scripting and bulk transformations. I use sed for find-and-replace across files, line deletion, and text substitution in pipelines. Here is what I use regularly. The Substitute Command The command I use most is s , for substitute. It replaces the first match of a pattern on each line with a replacement string. Adding the g flag at the end replaces all matches on the line, not just the first. # Replace the first occurrence per line sed 's/foo/bar/' file.txt # Replace all occurrences per line sed 's/foo/bar/g' file.txt The delimiter is normally a slash, but when the pattern or replacement contains slashes, I use a different delimiter to avoid escaping. A pipe or hash works well. # Replace a URL using a different delimiter sed 's|/old/path|/new/path|g' config.txt This is cleaner than escaping…