Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"
Linux Magazine: The source for advanced Linux know-how

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents

· Introduction to Operating Systems
· Linux Basics
· Working with the System
· Shells and Utilities
· Editing Files
· Basic Administration
· The Operating System
· The X Windowing System
· The Computer Itself
· Networking
· System Monitoring
· Solving Problems
· Security
· Installing and Upgrading
· Linux and Windows

Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
Copyright Info
Terms of Use
Privacy Info
Masthead / Impressum
Your Account

Private Messages

News Archive
Submit News
User Articles
Web Links


The Web

Who's Online
There are currently, 58 guest(s) and 0 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here




          psed [-an] script [file ...]
          psed [-an] [-e script] [-f script-file] [file ...]

          s2p  [-an] [-e script] [-f script-file]


       A stream editor reads the input stream consisting of the
       specified files (or standard input, if none are given),
       processes is line by line by applying a script consisting
       of edit commands, and writes resulting lines to standard
       output. The filename `"-"' may be used to read standard

       The edit script is composed from arguments of -e options
       and script-files, in the given order. A single script
       argument may be specified as the first parameter.

       If this program is invoked with the name s2p, it will act
       as a sed-to-Perl translator. See "sed Script Translation".

       sed returns an exit code of 0 on success or >0 if an error


       -a  A file specified as argument to the w edit command is
           by default opened before input processing starts.
           Using -a, opening of such files is delayed until the
           first line is actually written to the file.

       -e script
           The editing commands defined by script are appended to
           the script.  Multiple commands must be separated by

       -f script-file
           Editing commands from the specified script-file are
           read and appended to the script.

       -n  By default, a line is written to standard output after
           the editing script has been applied to it. The -n
           option suppresses automatic printing.


       sed command syntax is defined as


       with whitespace being permitted before or after addresses,
       and between the function character and the argument. The
       addresses and the address inverter ("!") are used to
       restrict the application of a command to the selected

       A sed address is either a line number or a pattern, which
       may be combined arbitrarily to construct ranges. Lines are
       numbered across all input files.

       Any address may be followed by an exclamation mark
       (`"!"'), selecting all lines not matching that address.

           The line with the given number is selected.

       $   A dollar sign ("$") is the line number of the last
           line of the input stream.

       /regular expression/
           A pattern address is a basic regular expression (see
           "Basic Regular Expressions"), between the delimiting
           character "/".  Any other character except "\" or new­
           line may be used to delimit a pattern address when the
           initial delimiter is prefixed with a backslash

       If no address is given, the command selects every line.

       If one address is given, it selects the line (or lines)
       matching the address.

       Two addresses select a range that begins whenever the
       first address matches, and ends (including that line) when
       the second address matches.  If the first (second) address
       is a matching pattern, the second address is not applied
       to the very same line to determine the end of the range.
       Likewise, if the second address is a matching pattern, the
       first address is not applied to the very same line to
       determine the begin of another range. If both addresses
       are line numbers, and the second line number is less than
       the first line number, then only the first line is


       The maximum permitted number of addresses is indicated
       with each function synopsis below.

       The argument text consists of one or more lines following
       the command.  Embedded newlines in text must be preceded
       with a backslash.  Other backslashes in text are deleted
       and the following character is taken literally.

       [1addr]a\ text
           Write text (which must start on the line following the
           command) to standard output immediately before reading

           Deletes the pattern space and starts the next cycle.

           Deletes the pattern space through the first embedded
           newline or to the end.  If the pattern space becomes
           empty, a new cycle is started, otherwise execution of
           the script is restarted.

           Replace the contents of the pattern space with the
           hold space.

           Append a newline and the contents of the hold space to
           the pattern space.

           Replace the contents of the hold space with the pat­
           tern space.

           Append a newline and the contents of the pattern space
           to the hold space.

       [1addr]i\ text
           Write the text (which must start on the line following
           the command) to standard output.

           Print the contents of the pattern space: non-printable
           characters are shown in C-style escaped form; long
           lines are split and have a trailing `"\"' at the point
           of the split; the true end of a line is marked with a
           `"$"'. Escapes are: `\a', `\t', `\n', `\f', `\r', `\e'
           for BEL, HT, LF, FF, CR, ESC, respectively, and `\'
           followed by a three-digit octal number for all other
           non-printable characters.

           If automatic printing is enabled, write the pattern
           space to the standard output. Replace the pattern
           space with the next line of input. If there is no more
           input, processing is terminated.

           Append a newline and the next line of input to the
           pattern space. If there is no more input, processing
           is terminated.

           Print the pattern space to the standard output. (Use
           diately before the next attempt to read a line of
           input. Any error encountered while reading file is
           silently ignored.

       [2addr]s/regular expression/replacement/flags
           Substitute the replacement string for the first sub­
           string in the pattern space that matches the regular
           expression.  Any character other than backslash or
           newline can be used instead of a slash to delimit the
           regular expression and the replacement.  To use the
           delimiter as a literal character within the regular
           expression and the replacement, precede the character
           by a backslash (`"\"').

           Literal newlines may be embedded in the replacement
           string by preceding a newline with a backslash.

           Within the replacement, an ampersand (`"&"') is
           replaced by the string matching the regular expres­
           sion. The strings `"\1"' through `"\9"' are replaced
           by the corresponding subpattern (see "Basic Regular
           Expressions").  To get a literal `"&"' or `"\"' in the
           replacement text, precede it by a backslash.

           The following flags modify the behaviour of the s com­

           g       The replacement is performed for all matching,
                   non-overlapping substrings of the pattern

           1..9    Replace only the n-th matching substring of
                   the pattern space.

           p       If the substitution was made, print the new
                   value of the pattern space.

           w file  If the substitution was made, write the new
                   value of the pattern space to the specified

       [2addr]t [label]
           Branch to the : function with the specified label if
           any s substitutions have been made since the most
           recent reading of an input line or execution of a t
           function. If no label is given, branch to the end of
           the script.

       [2addr]w file
           The contents of the pattern space are written to the

           first command may be given on the same line as the
           opening { command. The commands within the list are
           jointly selected by the address(es) given on the {
           command (but may still have individual addresses).

       [0addr]# [comment]
           The entire line is ignored (treated as a comment). If,
           however, the first two characters in the script are
           `"#n"', automatic printing of output is suppressed, as
           if the -n option were given on the command line.


       A Basic Regular Expression (BRE), as defined in POSIX
       1003.2, consists of atoms, for matching parts of a string,
       and bounds, specifying repetitions of a preceding atom.


       The possible atoms of a BRE are: ., matching any single
       character; ^ and $, matching the null string at the begin­
       ning or end of a string, respectively; a bracket expres­
       sions, enclosed in [ and ] (see below); and any single
       character with no other significance (matching that char­
       acter). A \ before one of: ., ^, $, [, *, \, matching the
       character after the backslash. A sequence of atoms
       enclosed in \( and \) becomes an atom and establishes the
       target for a backreference, consisting of the substring
       that actually matches the enclosed atoms.  Finally, \ fol­
       lowed by one of the digits 0 through 9 is a backreference.

       A ^ that is not first, or a $ that is not last does not
       have a special significance and need not be preceded by a
       backslash to become literal. The same is true for a ],
       that does not terminate a bracket expression.

       An unescaped backslash cannot be last in a BRE.


       The BRE bounds are: *, specifying 0 or more matches of the
       preceding atom; \{count\}, specifying that many repeti­
       tions; \{minimum,\}, giving a lower limit; and \{mini­
       mum,maximum\} finally defines a lower and upper bound.

       A bound appearing as the first item in a BRE is taken lit­

       Bracket Expressions

       A bracket expression is a list of characters, character
       ranges and character classes enclosed in [ and ] and
       matches any single character from the represented set of
          cntrl     print     xdigit

       enclosed in [: and :] and represents the set of characters
       as defined in ctype(3).

       If the first character after [ is ^, the sense of matching
       is inverted.

       To include a literal `"^"', place it anywhere else but
       first. To include a literal '"]"' place it first or imme­
       diately after an initial ^. To include a literal `"-"'
       make it the first (or second after ^) or last character,
       or the second endpoint of a range.

       The special bracket expression constructs "[[:<:]]" and
       "[[:>:]]" match the null string at the beginning and end
       of a word respectively.  (Note that neither is identical
       to Perl's `\b' atom.)

       Additional Atoms

       Since some sed implementations provide additional regular
       expression atoms (not defined in POSIX 1003.2), psed is
       capable of translating the following backslash escapes:

       \< This is the same as "[[:>:]]".
       \> This is the same as "[[:<:]]".
       \w This is an abbreviation for "[[:alnum:]_]".
       \W This is an abbreviation for "[^[:alnum:]_]".
       \y Match the empty string at a word boundary.
       \B Match the empty string between any two either word or
       non-word characters.

       To enable this feature, the environment variable
       PSEDEXTBRE must be set to a string containing the
       requested characters, e.g.: "PSEDEXTBRE='<>wW'".


       The environment variable "PSEDEXTBRE" may be set to extend
       BREs.  See "Additional Atoms".


       ambiguous translation for character `%s' in `y' command
           The indicated character appears twice, with different

       `[' cannot be last in pattern
           A `[' in a BRE indicates the beginning of a bracket

       `\' cannot be last in pattern
           A `\' in a BRE is used to make the subsequent charac­
           The command has more than the permitted number of

       extra characters after command (%s)
       illegal option `%s'
       improper delimiter in s command
           The BRE and substitution may not be delimited with `\'
           or newline.

       invalid address after `,'
       invalid backreference (%s)
           The specified backreference number exceeds the number
           of backreferences in the BRE.

       invalid repeat clause `\{%s\}'
           The repeat clause does not contain a valid integer
           value, or pair of values.

       malformed regex, 1st address
       malformed regex, 2nd address
       malformed regular expression
       malformed substitution expression
       malformed `y' command argument
           The first or second string of a y command  is syntac­
           tically incorrect.

       maximum less than minimum in `\{%s\}'
       no script command given
           There must be at least one -e or one -f option speci­
           fying a script or script file.

       `\' not valid as delimiter in `y' command
       option -e requires an argument
       option -f requires an argument
       `s' command requires argument
       start of unterminated `{'
       string lengths in `y' command differ
           The translation table strings in a y commanf must have
           equal lengths.

       undefined label `%s'
       unexpected `}'
           A } command without a preceding { command was encoun­

       unexpected end of script
           The end of the script was reached although a text line
           after a a, c or i command indicated another line.

       unknown command `%s'
       unterminated `['
           A BRE contains an unterminated bracket expression.

          #no autoprint
          s/^.*Warn( *"\([^"]*\)".*$/\1/
          t process
          s/^/=item /

       on the program's own text, and piping the output into
       "sort -u".


       If this program is invoked with the name s2p it will act
       as a sed-to-Perl translator. After option processing (all
       other arguments are ignored), a Perl program is printed on
       standard output, which will process the input stream (as
       read from all arguments) in the way defined by the sed
       script and the option setting used for the translation.


       perl(1), re_format(7)


       The l command will show escape characters (ESC) as `"\e"',
       but a vertical tab (VT) in octal.

       Trailing spaces are truncated from labels in :, t and b

       The meaning of an empty regular expression (`"//"'), as
       defined by sed, is "the last pattern used, at run time".
       This deviates from the Perl interpretation, which will re-
       use the "last last successfully executed regular expres­
       sion". Since keeping track of pattern usage would create
       terribly cluttered code, and differences would only appear
       in obscure context (where other sed implementations appear
       to deviate, too), the Perl semantics was adopted. Note
       that common usage of this feature, such as in
       "/abc/s//xyz/", will work as expected.

       Collating elements (of bracket expressions in BREs) are
       not implemented.


       This sed implementation conforms to the IEEE
       Std1003.2-1992 ("POSIX.2") definition of sed, and is com­
       patible with the OpenBSD implementation, except where oth­
       erwise noted (see "BUGS").




Security Code
Security Code
Type Security Code

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!

Amazon Wish List

Did You Know?
The Linux Tutorial welcomes your suggestions and ideas.


Tell a Friend About Us

Bookmark and Share

Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.11 Seconds