The stream editor sed

TEXT TEMPLATES

Article from Issue 59/2005
Author(s):

Working with a text editor can be difficult if you need to handle frequently recurring tasks or multiple files. sed can save a lot of typing.

The Streamline Editor is a popular text editor for Unix and Linux systems. In contrast to editors such as Vi and Emacs, sed is not interactive. Instead, users define text to delete, modify, or add at the command line. You can also script sed commands and run them as a single batch job. If you need to modify a number of characters in one or multiple files, sed saves you from typing till your fingers bleed.

sed normally reads texts for processing from standard input (stdin), however, you can alternatively specify one or multiple files. sed will apply the specified commands to each line, writing them to a buffer. The output of the buffer will be sent to standard output (stdout), unless you change the default. The generic command syntax is as follows:

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Command Line: tr & dos2unix

    The tr tool is a real wizard. This simple command lets you replace strings in text files. Whether you are replacing letters or just removing whitespace, you will be amazed at tr‘s versatility.

  • Command Line: Diffutils

    The Diffutils tool set helps you compare text files, discover and display the differences between files, and even automatically synchronize files.

  • Command Line: Vim

    Vim feels at home with any Linux distribution. This text mode only editor, which completely does without a mouse, is a useful aid for command line fans.

  • Command Line: File Viewers

    Practical tools such as cat, less, and head are convenient for viewing text.

  • Bash Data Gathering

    With some simple Bash commands, you can gather, parse, and filter text data into CSV files ready for your favorite statistical application.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News