Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Sed
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Mode of operation== sed is a line-oriented text processing utility: it reads text, line by line, from an [[input stream]] or file, into an internal buffer called the ''pattern space''. Each line read starts a ''cycle''. To the pattern space, sed applies one or more operations which have been specified via a ''sed script''. sed implements a [[programming language]] with about 25 ''commands'' that specify the operations on the text. For each input line, after running the script, sed ordinarily outputs the pattern space (the line as modified by the script) and begins the cycle again with the next line. Other end-of-script behaviors are available through sed options and script commands, e.g. <code>d</code> to delete the pattern space, <code>q</code> to quit, <code>N</code> to add the next line to the pattern space immediately, and so on. Thus a sed script corresponds to the body of a loop that iterates through the lines of a stream, where the loop itself and the loop variable (the current line number) are implicit and maintained by sed. The sed script can either be specified on the [[command line]] (<code>-e</code> option) or read from a separate file (<code>-f</code> option). Commands in the sed script may take an optional ''address,'' in terms of line numbers or [[regular expression]]s. The address determines when the command is run. For example, <code>2d</code> would only run the <code>d</code> (delete) command on the second input line (printing all lines but the second), while <code>/^ /d</code> would delete all lines beginning with a space. A separate special buffer, the ''hold space'', may be used by a few sed commands to hold and accumulate text between cycles. sed's command language has only two variables (the "hold space" and the "pattern space") and [[GOTO]]-like branching functionality; nevertheless, the language is [[Turing-complete]],<ref>{{cite web | title = Implementation of a Turing Machine as Sed Script | url = http://sed.sourceforge.net/grabbag/scripts/turing.txt | access-date = 2003-04-24 | archive-date = 2018-02-20 | archive-url = https://web.archive.org/web/20180220011912/http://sed.sourceforge.net/grabbag/scripts/turing.txt | url-status = dead }}</ref><ref>{{cite web | title = Turing.sed | url = http://sed.sourceforge.net/grabbag/scripts/turing.sed | access-date = 2003-04-24 | archive-date = 2018-01-16 | archive-url = https://web.archive.org/web/20180116201401/http://sed.sourceforge.net/grabbag/scripts/turing.sed | url-status = dead }}</ref> and [[esoteric programming|esoteric]] sed scripts exist for games such as [[sokoban]], [[arkanoid]],<ref name="gamez">{{cite web | url = http://sed.sourceforge.net/#gamez | title = The $SED Home - gamez }} </ref> [[chess]],<ref>{{cite web |title=bolknote/SedChess |url=https://github.com/bolknote/SedChess |access-date=August 23, 2013 |website=GitHub}}</ref> and [[tetris]].<ref name="tetris"> {{cite web |title=Sedtris, a Tetris game written for sed |url=https://github.com/uuner/sedtris |access-date=October 3, 2016 |website=[[GitHub]]}}</ref> A [[main loop]] executes for each line of the input stream, evaluating the sed script on each line of the input. Lines of a sed script are each a pattern-action pair, indicating what pattern to match and which action to perform, which can be recast as a [[Conditional (computer programming)|conditional statement]]. Because the main loop, working variables (pattern space and hold space), input and output streams, and default actions (copy line to pattern space, print pattern space) are implicit, it is possible to write terse [[one-liner program]]s. For example, the sed program given by: 10q will print the first 10 lines of input, then stop.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Sed
(section)
Add topic