Home >> Computers >> Software >> Editors >> SED




sed (which stands for Stream EDitor) occurs as elementary however mighty computer program used to apply various pre-specified textual transformations to the consecutive stream of text information. It reads input files line by line, edits apiece line based on data from system specified within its elementary language (a sed script), then outputs a line. Piece originally created as a UNIX utility by Lee E. McMahon of Bell Labs in 1973/1974, sed is now available for virtually each operating models that supports the command line.

sed is typically thought of as a non-interactive text editor. It differs from either conventional text editors within that a processing of the 2 inputs is inverted. Instead of iterating it used to be that across a listings of edit commands using for both 1 one to the totally document inside memory, sed iterates when through the document using the whole listing of edit commands to each line. Because simply of these line at one time is within memory, sed can run arbitrarily-big document.

sed's command placed is modeled when a ed editor, and virtually all commands function likewise therein anatropous paradigm. For instance, a command 25d means ''in case this is line Xxv, so delete (don't output) it, like than attend line Xxv & delete it'' when it does inside ed. the notable exception is the copy & move commands, which span a range of lines & so don't use at times straight-forward equivalents around sed. Instead, sed introduces an extra buffer known as a hang on to space, & extra commands to manipulate it. A ed command to copy line Twenty-five to line 76 (25t76) for instance would exist when coded as deuce separate commands around sed (25h; 76g), to store a line in a hang on to space until the point at which it should become retrieved.

the ensuing case shows a average usage of sed: sed -e 's/oldstuff/newstuff/g' inputFileName > outputFileName

A s stands for substitute; a g stands for spherical, which means that whole matching occurrences in the line would become replaced. When a foremost slash is the regular expression to search for & when a 2nd slash is the expression to replenish it sustaining. A substitute comm& (s///) is out and away a virtually all mighty and virtually all normally utilized sed command.

Under Unix, sed is typically utilized as a filter in a pipeline: generate_data | sed -e 's/x/y/' That is, generate a information, however produce a chump change of replacing x by owning y.

Many substitutions or even more commands may be together inside the file known as, for instance, subst.sed and so exist as applied like sed -f subst.sed inputFileName > outputFileName

Besides substitution, more forms of elementary processing come conceivable. E.g., a as a result script deletes empty lines or even lines that sole contain spaces:

sed -e '/^ *$/d' inputFileName

This case utilized a select few of the charted regular expression metacharacters: ^ Matches a beginning of the line $ Matches a prevent of the line . Matches any lone character * Matches zero or even supplementary occurrences of the last character [ ] Matches any of the characters within the [ ]

Complex sed constructs come conceivable, to the extent that it may be ideate as a extremely specialized, albeit elementary, programming language. Flow of control, for instance, may exist as managed by utilize of a label (a colon followed by the string which is to be the label title) & the branch instruction b; an instruction b followed by a valid label title may move processing to a prevent ensuing a label; in case a label doesn't survive so the branch may prevent the script.

sed is one of a super early Unix commands that permitted command line processing of information files. It evolved when a natural successor to the popular grep command. First cousin to the late AWK, sed allowed powerful & interesting information processing to exist as handle casing scripts. Sed was probably a earliest Unix convienence that really encouraged regular expressions to exist as utilized ubiquitously. Around terms of speed of operation, sed is usually sooner than perl inside execution & markedly sooner than AWK.

sed & AWK come typically cited when a primogenitor & inspiration for Perl; in particular a s/// syntax from either a lesson above is section of Perl's syntax.

sed's language doesn't keep around variables & has just primitive GOTO and branching functionality; nevertheless, a language is Turing-complete.

GNU sed includes several recently features like around-place redaction of files (i personally.e., replenish a original file by using a effect of using a sed program). Around-place redaction is typically utilized instead of ed scripts: for example,

sed -we 's/abc/def/' file

may be utilized instead of

ed file Single,$ s/abc/def/ w q

There exists a long version of sed known as Extremely-sed (ssed) that includes regular expressions compatible with Perl. Samples
In that lessin it might allow sed which ordinarily simply works on of these line, to dislodge up to date lines from either sentences in which the 2nd phrase starts by using a space.

Assume a as punishment text. This is the cat our cat's title is betty This is the dog the pooch's title is frank

A sed command in the image below might let it run into This is the cat the cat's title is betty This is our puppy our pooch's title is frank

On this button's a command: sed 'North;s/\n //g;P;D;'

North understand next line (s) substitute (\n )match \n & space (P) so print retired a next line wise shoppers scroll through & run it (D) delete it and then it doesn't output twice.

SED, the Stream Editor
Eric Pement's Cornerstone Mag site hosts an extensive FAQ, download sites for most operating systems, large list of handy one-liners, table of version differences, exhaustive links.

GNU SED version 3.02.80 for OS/2
A port of the program for OS/2, requires RPM and EMX.

SED Tutorials
Some items selected by Yiorgos Adamopoulos from the Seders grab bag and mailing list.

SED & AWK
The most popular book on the stream editor, from O'Reilly.

Custom SED Proposal
Wish list and manifesto for development of a new version of the editor.

SED FAQ (He Sed She Sed)
Dreamwvr.com's alternate frequently asked questions list is arranged in increasing order of difficulty, and can be read as a tutorial.

Roger Chang's SED and Shell Scripts
SED and Bourne Shell scripts by a seder in Taiwan.

Batch and Third-Party Programs
Benny Pedersen gives examples of the use of SED in DOS batch files.

SED
The Open Group "Single UNIX Specification" man page.


Computers: Software: Operating Systems: Unix






© 2005 GeneralAnswers.org