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: Diffutils

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

  • Command Line: File Viewers

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

  • 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: Mailx

    The simple mailx command-line mail client handles mail either interactively or via command-line options. Although it lacks the convenience of a GUI-based tool, mailx compares well in scripting.

  • Command Line: FTP and NcFTP

    FTP and NcFTP are both FTP clients for the command line. While FTP only has basic file transfer functionality, NcFTP has a whole bunch of additional features.

comments powered by Disqus

Direct Download

Read full article as PDF:

Commandline_sed.pdf (39.77 kB)

News