Skip to Content
Small, Sharp Software Tools
book

Small, Sharp Software Tools

by Brian P. Hogan
June 2019
Intermediate to advanced
328 pages
7h 27m
English
Pragmatic Bookshelf
Content preview from Small, Sharp Software Tools

Editing Streams with sed

If you need to modify text in a pipeline or in a file, sed is your best friend. Its name is short for “stream editor” and it’s very handy. While you can do many things with sed, the most common use is to replace some text with other text, similar to how you’d use the find and replace feature in your text editor.

Like other tools, sed can read its input from a file or from standard input. Try it out. Print out “Hello World” and use sed to replace “Hello” with “Goodbye”:

 $ ​​echo​​ ​​"Hello World"​​ ​​|​​ ​​sed​​ ​​-e​​ ​​'s/Hello/Goodbye/'
 Goodbye World

In this example, you’re sending “Hello World” via a pipe and then using the -e flag to specify an expression. The expression s/Hello/Goodbye/ is a basic substitution. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The VimL Primer

The VimL Primer

Benjamin Klein
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz

Publisher Resources

ISBN: 9781680507003Errata Page