1. GENERAL INFORMATION
back to FAQ index
1.1. Introduction - How this FAQ is organized
This FAQ is organized to answer common (and some uncommon)
questions about sed, quickly. If you see a term or abbreviation in
the examples that seems unclear, see if the term is defined in
section 1.5. If not, write us and we'll try to clarify it for the
next version of the FAQ.
1.2. Latest version of the sed FAQ
The newest version of the sed FAQ is usually here:
http://www.cornerstonemag.com/sed/sedfaq.html
http://www.cornerstonemag.com/sed/sedfaq.txt
http://www.dbnet.ece.ntua.gr/~george/sed/sedfaq.html
http://www.dbnet.ece.ntua.gr/~george/sed/sedfaq.txt
http://www.ptug.org/sed/sedfaq.html
http://www.faqs.org/faqs/editor-faq/sed
ftp://rtfm.mit.edu/pub/faqs/editor-faq/sed
Another FAQ file on sed by a different author can be found here:
http://www.dreamwvr.com/sed-info/sed-faq.html
1.3. FAQ revision information
Changes to this FAQ since the last version are indicated by a
vertical bar (|) placed in column 78 of the affected lines. To
remove the vertical bars (use double quotes for MS-DOS):
sed 's/ *|$//' sedfaq.txt > sedfaq2.txt
In the HTML version, vertical bars do not appear. New or altered
portions of the FAQ are indicated by printing in dark blue type.
In the text version, words needing emphasis may be surrounded by
the underscore '_' or the asterisk '*'. In the HTML version, these
are changed to italics and boldface, respectively.
1.4. How do I add a question/answer to the sed
FAQ?
Word your question succinctly and clearly, and e-mail it Eric
Pement <epement@jpusa.org>, indicating your proposed addition to
the FAQ. We'll post it on the sed-users mailing list (see section
2.3.2, below) and discuss it there. If some agreement, your
contribution will be included in the next edition of the FAQ.
1.5. FAQ abbreviations:
files = one or more filenames, separated by whitespace
RE = Regular Expressions supported by sed
LHS = the left-hand side ("find" part) of "s/find/repl/" command
RHS = the right-hand side ("replace" part) of "s/find/repl/" cmd.
files: "files" stands for one or more filenames entered on the
command line. The names may include any wildcards your shell
understands (such as ``zork*'' or ``Aug[4-9].let''). Sed will
process each filename passed to it by the shell.
RE: For the syntax of Basic Regular Expressions (BREs), type "man
ed" and read the documentation for regular expressions. A technical
description of BREs from the Single UNIX Specification, Version 2,
by The Open Group (joint committee on Unix) is available online at
<http://www.opengroup.org/onlinepubs/7908799/xbd/re.html#tag_007_003>.
Sed normally supports BREs plus '\n' to match a newline in the
pattern space and '\xREx' as equivalent to '/RE/', where 'x' is any
character other than another backslash.
Some versions of sed support supersets of BREs, or "extended
regular expressions", which offer additional metacharacters for
increased flexibility. For additional information on extended REs
in GNU sed, see sections 3.7 ("GNU/POSIX extensions to regular
expressions") and 6.8.3 ("Special syntax in REs"), below.
LHS: In sed, the LHS may be a string literal (e.g., "foo") or any
valid regular expression supported by your version of sed. Some
versions of sed support things like \t for TAB, \r for carriage
return, \xNN for direct entry of hex codes, etc. Other versions of
sed do not support this syntax.
RHS: The right-hand side (the replacement part in s/find/replace/)
is almost always a string literal, with no interpolation of the
metacharacters (.), (^), ($), ([), or \(...\) -- with the following
exceptions: \1 through \9 are replaced by the corresponding group,
if grouping \(...\) was used in the LHS. If no grouping was used
in the LHS, then \1 through \9 are replaced by literal digits. '&'
is replaced by the entire expression matched on the LHS. To enter a
literal ampersand or backslash in the RHS, type '\&' or '\\'.
1.6. Credits and acknowledgements
My time spent messing with sed, composing this FAQ, and generally
doing text manipulation which is unrelated to my job description is
due to the kind tolerance of the Christian magazine I work for,
Cornerstone. So, let me say thanks to the mag staff for indulging
this somewhat unusual "ministry." Please visit this site:
http://www.cornerstonemag.com
Many of the ideas for this FAQ were taken from the Awk FAQ
http://www.faqs.org/faqs/computer-lang/awk/faq/
ftp://rtfm.mit.edu/pub/usenet/comp.lang.awk/faq
and from the Perl FAQ
http://www.perl.com/perl/FAQ
http://www.perl.com/CPAN/doc/FAQs/FAQ/html/index.html
ftp://ftp.cdrom.com/pub/perl/CPAN/doc/FAQs/
The following individuals have contributed significantly to this
document, and have provided input and wording suggestions for
questions, answers, and script examples. Credit goes to these
contributors (in alphabetical order by last name):
Al Aab <af137@freenet*toronto*on*ca>
Yiorgos Adamopoulos <adamo@softlab*ece*ntua*gr>
Walter Briscoe <walter@wbriscoe*demon*co*uk>
Jim Dennis <jadestar@rahul*net>
Carlos Duarte <cdua@algos*inesc*pt>
Otavio Exel <oexel@economatica*com*br>
Mark Katz <mark@ispc001*demon*co*uk>
Eric Pement <epement@jpusa*org>
Greg Pfeiffer <gpfeiffe@yahoo*com>
Ken Pizzini <ken@halcyon*com>
Niall Smart <nialls@euristix*ie>
Simon Taylor <staylor@unisolve*com*au>
Greg Ubben <gsu@romulus*ncsc*mil>
Note: Periods (.) are replaced with asterisks (*) to foil e-mail
harvesting and spam-bots.
1.7. Standard disclaimers
While a serious attempt has been made to ensure the accuracy of the
information presented herein, the contributors and maintainers of
this document do not claim the absence of errors and make no
warranties on the information provided. If you notice any errors or
ambiguous wording, please notify the FAQ maintainer so it can be
fixed for the next edition.