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!
===Substitution command=== The following example shows a typical, and the most common, use of sed: substitution. This usage was indeed the original motivation for sed:<ref name=early_history /> <syntaxhighlight lang=bash> sed 's/regexp/replacement/g' inputFileName > outputFileName </syntaxhighlight> In some versions of sed, the expression must be preceded by <code>-e</code> to indicate that an expression follows. The <code>s</code> stands for substitute, while the <code>g</code> stands for global, which means that all matching occurrences in the line would be replaced. The [[regular expression]] (i.e. pattern) to be searched is placed after the first delimiting symbol (slash here) and the replacement follows the second symbol. Slash (<code>/</code>) is the conventional symbol, originating in the character for "search" in ed, but any other could be used to make syntax more readable if it does not occur in the pattern or replacement; this is useful to avoid "[[leaning toothpick syndrome]]". The substitution command, which originates in search-and-replace in ed, implements simple parsing and [[templating language|templating]]. The <code>regexp</code> provides both pattern matching and saving text via sub-expressions, while the <code>replacement</code> can be either literal text, or a format string containing the characters <code>&</code> for "entire match" or the special [[escape sequence]]s <code>\1</code> through <code>\9</code> for the ''n''th saved sub-expression. For example, <code>sed -r "s/(cat|dog)s?/\1s/g"</code> replaces all occurrences of "cat" or "dog" with "cats" or "dogs", without duplicating an existing "s": <code>(cat|dog)</code> is the 1st (and only) saved sub-expression in the regexp, and <code>\1</code> in the format string substitutes this into the output.
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